C Programming

Q.1 Write the programme to find the area of triangle using 3 sides?

Solution

#include<stdio.h>
#include<conio.h>
#inlcude<math.h>
void main()
{
int side1,side2,side3,S,AOT;
clrscr();
printf("enter the value of side1");
scanf("%d",&side1);
printf("enter the value of side2");
scanf("%d",&side2);
printf("enter the value of side3");
scanf("%d",&side3);
s=(side1+side2+side3)/2;
AOT=sqrt(s*(s-side1)*(s-side2)*(s-side3));
printf("the AOT is %d",AOT);
getch();
}
    
Output
enter the value of side1 10
enter the value of side2 10
enter the value of side3 10
the AOT is 20




Q.2 Write a programme to find the value of a+b and a*b?

Solution
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,sum=0,prod=0;
clrscr();
printf("enter the value of a");
scanf("%d",&a);
printf("enter the value of b");
scanf("%d",&b);
sum=a+b;
prod=a*b;
printf("\nsum of a and b is %d" ,sum);
printf("\nprod of a and b is %d",prod);
getch();
}

Output 
enter the value of a 12
enter the value of b 12

sum of a and b is 24
prod of a and b is 144




Q.3 Write the programme to convert the temperature from Fahrenheit to Celsius?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
float c=0,f=0;
clrscr();
printf("\nenter the value of f\n");
scanf("%f",&f);
printf("\n%f\n",f);
c= (5.0/9.0)*(f-32.0);
printf("\n the value of c is %f \n",c);
getch();
}

Output

enter the value of f
50

50.000000

 the value of c is 10.000000
 
 


Q.4 Write the programme to find the percentage of 5 subject?

Solution
#include<stdio.h>
#include<conio.h>
int main()
{
int math,eng,sst,bio,lang,sum=0,per=0;
clrscr();
printf("enter the marks of math");
scanf("%d",&math);    
printf("enter the marks of eng");
scanf("%d",&eng);
printf("enter the marks of sst");
scanf("%d",&sst);
printf("enter the marks of bio");
scanf("%d",&bio);
printf("enter the marks of lang");
scanf("%d",&lang);
sum = (math+eng+sst+bio+lang);
printf("the value of sum is %d",sum);
per =(sum/5);
printf("\n per of marks is %d",per);
getch();
}

Output
enter the marks of math 50
enter the marks of eng 50
enter the marks of sst 50
enter the marks of bio 50
enter the marks of lang 50
the value of sum is 250
per of marks is 50




Q.5 Write a programme to display the value of a character?


Solution
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
clrscr();
printf("enter the value of a:");
scanf("%c",a);
getch();
}

Output
enter the value of a: Kunal Singh


 

Q.6 Write a programme for finding the sales commission?


Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int sales;
float comm;
clrscr();
printf("sales amount");
scanf("%d",&sales);
if (sales<=500)
comm=0.05*sales;
else if(sales<=2000)
comm=35+0.10*(sales-500);
else if(sales<=5000)
comm=185+0.125*(sales-2000);
else
comm=0.125*sales;
printf("\n commision amount is Rs.= %0.2f",comm);
getch();
}

Output
sales amount 4500
commision amount is Rs.=497.50


 

Q. 7 write a programme find the value of Y implement through switch case?

Solution
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
float  x,y;
clrscr();
printf("enter the value of x and n");
scanf("%f%d",&x,&n);
switch(n)
{
case1 : y=1+x;
break;
case2 : y=1+(x/n);
break;
case3 : y=1+pow(x,n);
break;
default : y=1+(x*n);
break;
}
printf("\n the value of y(x,n)=%6.2f",y);
getch();
}

Output

enter the value of x and n 1
2
the value of y(x,n)=3


 

Q.8 write a programme find the larger number in two number?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter a and b values");
scanf("%d%d",&a,&b);
a>b?printf("%d",a):printf("%d",b);
getch();
}

Out put
Enter a and b values
6
7
7
  


 
Q.9 write a programme find the larger number in Three number ?


Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,big;
clrscr();
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is:%d",big);
getch();
}

Output

Enter any three numbers
4
5
6

The biggest number is : 6




Q.10 write a programme find the bigger number in three number ? By If else method?

Solution
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
int big;
clrscr();
printf("Enter any three numbers: "); 
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
big = a;
else if(b>c)
big = b;
else
big = c;   
printf("The Biggest number is: %d",big); 
getch();
}

Output:

Enter any there numbers:
13
25
6
The Biggest number is: 25




Q.11 Write our name?

Solution
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“\n Kunu”);
printf(“\n Kuku”);
printf(“\n Annie”);
printf(“\n Pepsi”);
printf(“\n Pooh”);
printf(“\n Shriq”);
printf(“\n Suhail”);
printf(“\n Kavish”);
printf(“\n Atul”);
printf(“\n Devil”);
printf(“\n Nitin”);
printf(“\n Ashita”);
printf(“\n Atul”);
getch();
}
           
Out put
Kunu
Kuku
Annie
Pepsi
Phoo
Shariq
Suhail
Kavish
Atul
Devil
Nitin
Ashita
Atul




Q.12. Write a program to show the sum of following series
S= 1+(1+2)+(1+2+3)+..............................(1+2+3+.......................N) 

Solution
#include<stdio.h>
#include<conio.h>
void main()
{
int  i,j,n,s,term;
clrscr();
printf ("Enter value of N:");
scanf ("%d",&n);
s=0;
for (i=0;i<n;i++)
{
term=0;
for (j=1;j<=i;j++)
{
term=term+j;
}
s=s+term;
}
printf("\n sum of series s=%d",s);
getch();
}

Output
Enter the value of N: 4
Sum of series: 10




Q.13 Write a program to show the odd number series?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
               int i,n;
               clrscr();
               printf("\nEnter range up to which u want to print :");
               scanf("%d",&n);
               for(i=1;i<n;i=i+2)
               {
               printf("\n%d",i);
               }
getch();
}




Out put
Enter range up to which u want to print : 10
           
1
3
5
7
9



 
Q.14. Write a program to find the roots of a quadratic equation?

Solution
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2,disc;
clrscr();
printf("Enter the co-efficients\n");
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;
if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("The roots are distinct\n");
}
if(disc==0)
{
x1=x2=-b/(2*a);
printf("The roots are equal\n");
printf("x1=%f\nx2=%f\n",x1,x2);
}
x1=-b/(2*a);
x2=sqrt(fabs(disc))/(2*a);
printf("The roots are complex\n");
printf("The first root=%f+i%f\n",x1,x2);
printf("The second root=%f-i%f\n",x1,x2);
getch();
}
 
Out put 
Enter the co-efficients:

                                                                                                                                      
 
 
15. Write a program to swap the values of two number?
 
Solution
 
#include<stdio.h>
#include<conio.h>
void main()
{
               int a,b;
               clrscr();
printf("\n Enter the Two numbers for swaping:");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\n a is %d”,a);
printf("\n b is %d”,b);
getch();
}

Out put

Enter the Two numbers for swaping : 6 9

a is 9b is 6




16. Write a program Generate the Fibonacci Series

Solution

#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
int n,i,c,a=0,b=1; 
clrscr();
printf("Enter Fibonacci series of nth term : "); 
scanf("%d",&n); 
printf("%d %d ",a,b); 
for(i=0;i<=(n-3);i++) 
{ 
c=a+b; 
a=b; 
b=c; 
printf("%d ",c); 
} 
getch(); 
} 



Out put

Enter Fibonacci series of nth term: 9
0 1 1 2 3 5 8 13 21




17. Write a program to Check weather the given number is a prime number  or not?

Solution

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int  num,i,count=0;
clrscr();
printf (“Enter a number:”);
scanf(“%d”,&num);
for (i=2;i<=num/2;i++)
{
            If(num%i==0)
{
            count++;
            break;
}
}
            if(count==0 && num!=1)
            printf(“%d is a prime number”,num);
            else
            printf(“%d is not a prime number”,num);
getch();
}


Out put

Enter a number:  3 is a prime number
Enter a number: 6 is not a prime number








 
18. Write a program to generate Pascal Triangle            

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int line,i,j,k;
clrscr();
printf(“Enter the number of line :”);
scanf(“%d”,&line);
for(i=1;i<=line;i++)
{
for(j=1;j<=line-i;j++)
printf(“ “);
for(k=1;k<i;k++)
printf(“%d”,k);
for(k=i;k>=1;k--)
printf(“%d”,k);
printf(“\n”);
}
getch();
}


Out put

Enter the number of line: 5

                                                1
                                    1          2          1
1          2          3          2          1
1          2          3          4          3          2          1
1          2          3          4          5          4          3          2          1



 
19. Write a program to print following pattern?
*
**
***
****
*****

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf(“Enter the value of n :”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf(“*”);
printf(“\n”);
}
getch();
}


Out put
Enter the value of n : 5

*
**
***
****
*****




20. Write a program to print following pattern?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int n,i,j;
clrscr();
printf(Enter the value of n :”);
scanf(“%d”,&n);
for (i=1; i<=n;i++)
{
for (j=1;j<=n-i;j++)
printf(“ “);
for(j=1;j<=i;j++)
printf(“*”);
for(j=1;j<i;j++)
printf(“ “);
printf(“\n”);
}
getch();         
}

Out put
Enter the value of n : 5

*
**
***
****
*****





 21. Write a program to print following pattern?
*
***
*****
*******
*********

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int i,j,n,p;
            clrscr();
printf(Enter the value of n :”);
scanf(“%d”,&n);
p=n;
for(i=1;i<=n;i++)
{
for(j=1;j<p;j++)
printf(“ “);
p--;
for(j=1;j<=2*i-1;j++)
printf(“*”);
printf(“\n”);
}
getch();
}

Out put
Enter the value of n: 5

*
***
*****
*******
********




22. Write a program to find the sum of digit of any given positive integers?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int num, k=1, sum=0;
clrscr();
printf("Enter the number whose digits are to be added :");
            scanf("%d",&num);
            while(num!=0)
            {
k=num%10;
sum=sum+k;
k=num/10;
num=k;
}
printf("Sum of the digits:%d \n",sum);
getch();
}

Out put
Enter the number whose digits are to be added: 2468
Sum of the digits: 20




23. Write a program to convert binary number into decimal number?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int n, nsave,rem=0,d=0,j=1,dec=0;
            clrscr();
            printf(“Enter the number in Binary :”);
            scanf(“%d”,&n);
            nsave=n;
            while(n>0)
            {
            rem=n%10;
            d=rem*j;
            dec=dec+d;
            j=j*2;
            n=n/10;
            }
printf(“ Binary number: =%d, Decimal number: =%d \n”,nsave,dec);
getch();
}


Out put
Enter the number in binary: 1101
Binary number: = 1101, Decimal number: = 13


 
 
24. Write a program to convert decimal number into binary number?

Solution

#include<stdio.h>
#include<conio.h>
void main ()
{
            int num, i =2, rem =0;
clrscr();
            printf(“Enter the decimal number :”);
            scanf(“%d”,&num);
            while ( num>0)
            {
            rem=num%i;
            num=num/i;
            printf(“%d”,rem);
            }
getch();
}



Out put
Enter the decimal number : 13
1101


 

25. Write a program to make Armstrong number?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int n,temp,d,arm=0;
            clrscr();
            printf(“\nEnter any number:”);
            scanf(“%d”,&n);
            temp=n;
            while(temp>0)
            {          
            d=temp%10;
            temp=temp/10;
            arm=arm+(d*d*d);
            }
            If(arm==n)
            printf(“\n\n%d is a Armstrong number \n”,n);
            else
            printf(“\n\n%d is not an Armstrong number \n”,n);
getch();
}



Out put
Enter any number : 320

320 is not an Armstrong number


 

26. Write a program to weather a string is palindrome or not

Solution

#include<stdio.h>
#include<conio.h>
#inlcude<string.h>
void main()
{
            char s1[20],s2[20];
            int result;
            clrscr();
            printf(“\nEnter any string:”);
            gets(s1);
            strcpy(s2,s1);
            strrev(s2);    
            result=strcmp(s1,s2);
            if(result==0)
            printf(“\n It is a Palindrome string”);
            else
            printf(“\n It is not a Palindrome string”);
getch();
}


Out put
Enter any string:



 
27. Write a program to find largest among N numbers?

Solution

#include<stdio.h>
#inlcude<conio.h>
void main ()
{
            int a[50],size,i,big;
            clrscr();
            printf(“\n Enter the size of the array :”);
            scanf(“%d”,&size);
            printf(“\n Enter elements into the array :”);
            for(i=0;i<size;i++)
            scanf(“%d”,&a[i]);
            big=a[0];
            for(i=1;i<size;i++)
            {
            if (big<a[i])
            big=a[i];
            }
            printf(“\n Biggest number : %d”,big);
getch();
}

Out put
Enter the size of the array: 5

Enter elements into the array: 6 14 13 12 4
Biggest number:  14




28. Write a program to calculate the Transpose of matrix?

Solution

#include<stdio.h>
#inlcude<conio.h>
void main ()
{
            int a[10][10],i,j,r,c;
            clrscr();
            printf(“\n Enter number of rows of columns :”);
            scanf(“%d%d”,&r,&c);
            printf(“\n Enter elements of Matrix:\n”);
            for(i=0; i<r ;i++)
for (j=0; j<c ; j++)
scanf(“%d”,&a[i][j]);
            printf(“\n\n Transpose of Matrix: \n\n”);
            for(i=0 ; i<c ; i++)
            {
            for (j=0;j<r;j++)
            printf(“\t%d”,a[j][i]);
            printf(“\n\n”);
            }
getch();
}

Out put
Enter  number of rows of columns : 2 2
Enter  elements of Matrix: 
6 9
5 8
Transpose of Matrix:
6          5
9          8




29. Write a program to multiply two matrices?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int a[10][10],b[10][10],c[10][10],i,j,k,r1,r2,c1,c2;
            back:
            printf(“\n Enter number of rows & columns of matrix A;”);
            scanf(“%d%d”,&r1,&c1);
            printf(“\n Enter number of rows & columns of matrix B:”);
            scanf(“%d%d”,&r2,&c2);
            if(c1!=r2)
            {
                        printf(“\n\n Multiplication is not possible \n”);
                        goto back;
            }
                        printf(“\n\n Enter elements of Matrix A:\n”);
                        for(i=0 ; i<r1 ; i++)
for(j=0 ; j<c2 ; j++)
scanf(“%d”,&a[i][j]);
printf(“\n Enter elements of matrix B:\n”);
for(i=0 ; i<r2; i++);
for(j=0 ; j<c2; j++);
scanf(“\n\n Elements of Matrix A: \n\n”);
for(i=0;i<r1;i++)
            {
for(j=0; j<c1;j++)
printf(“\t%d”,a[i][j]);
printf(“\n\n”);
}
printf(“\n\n Elements of Matrix B:\n”);
for(i=0;i<r2;i++)
{
            for(j=0;j<c2;j++)
            printf(“\t%d”,b[i][j]);
printf(“\n\n”);
}
                        for(i=0 ; i<r1;i++)
                        for(j=0 ; j<c2;j++)
            {
                        c[i][j]=0;
                        for(k=0;k<r2;k++)
                        c[i][j]=c[i][j]+a[i][k]*b[k][j];
            }
            printf(“\n\n multiplication of Matrices:\n\n;);
            for(i=0 ; i<r1; i++)
            {
                        for(j=0; j<c2; j++)
                        printf(“\t%d”,c[i][j]);
            }
getch();
}


           
Out put






30. Write a program to find the factorial of a give integer k?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
 int i=1,f=1,num;
clrscr();
printf("Enter a number: ");
scanf("%d",&num);
while(i<=num)
{
f=f*i;
i++;
}
printf("Factorial of %d is: %d",num,f);
getch();
}

Output:
Enter a number: 5
Factorial of 5 is: 120







31. Write a program to Sum of Two Matrices?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int a[10][10],b[10][10],c[10][10],i,j,row,col;
            clrscr();
            printf(“\n Enter no of rows & columns :”);
            scanf(“%d%d”,&row,&col);
            printf(“\n Enter elements of Array A :\n”);
            for(i=0,i<row;i++)
            for(j=0;j<col;j++)
            scanf(“%d”,&a[i][j]);
            printf(“\n Enter elements of Array B :\n”);
            for(i=0;i<row;i++)
            for(j=0;j<col;j++)
            scanf(“%d”,&b[i][j]);
            printf(“\n Elements of Matrix A:\n\n”);
            for(i=0;i<row;i++)
            {
                        for(j=0;j<col;j++)
                        printf(“\t%d”,a[i][j]);
                        printf(“\n\n”);
            }
            printf(“\n Elements of Matrix B : \n\n”);
            for(i=0;i<row;i++)
            {
                        for(j=0;j<col;j++)
                        printf(“\t%d”,b[i][j]);
                        printf(“\n\n”);
            }
            for(i=0;i<row;i++)
            for(j=0;j<col;j++)
            c[i][j]=a[i][j]+b[i][j];
            printf(“\n Matrix Addition is :\n\n”);
            for(j=0;j<col;j++)
            printf(“\t%d”,c[i][j]);
            printf(“\n”);
            }
getch();
}
Output:
  



32. Write a program to display ASCII value of given character?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter a character :”);
ch=getch();
printf(“\n\n ASCII values of %c is %u”,ch,ch,);
puts(“\n\n press any key to stop...”);
getch();
}


Out put
Enter a character : E
ASCII value of E is 69
press  any key to stop...
 
 


33. Write a program to calculate S.I. ?

Solution
#include<stdio.h>
#include<conio.h>
void main()
{
            int P,N,R,SI;
            printf(“Enter P,N,R;”);
            scanf(“%d%d%d”,&P,&N,&R);
            SI=(P*N*R)/100;
            Printf(“\n value of SI=%d”,SI);
getch();
}

Out put
Enter a P,N,R :
 20
10
60
Value of SI=120



 
34. Write a program the occurrence of a particular character in the         string given by the user?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            char st[20],ch;
            int count,l,i;
            clrscr();
            printf(“\n Enter the string :”);
            gets(st);
            printf(“\n Which character to be counted?”);
            scanf(“%c”,&ch);
            l=strlen(st);
            count=0;
            for(i=0;i<l;i++)
            it(st[i]==ch)
            count++;
            printf(“\n The character %c occurs %d times”,ch,count);
getch();
}

Out put
Enter the string : mohandas
 Which character to be counted? a
The character a occurs 2 times




35.       Write a program to find Greatest common divisor?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d1,d2,d3;
int gcd(int,int);
clrscr();
printf(“\n Enter three numbers :”);
scanf(“%d%d%d,&a,&b,&c);
d1=gcd(a,b);
d2=gcd(a,c);
d3=gcd(b,c);
if(d1==d2)
if(d1==d3)
printf(“\n Gretest common divisior is %d”,d1);
else
printf(“\n Gretest common divisior is %d”,gcd(d1,d3));
else
printf(“\n Gretest common divisior is %d”,gcd(d1,d2));
printf(“\n\n Press any key to continue......”);
getch();
}
int gcd(intx,inty);
{
            int nr,dr,r;
            if(x>=y)
{
            nr=x;
            dr=y;
}
else
{
            nr=y;
            dr=x;
}
            r=nr%dr
            while(r!=0)
{
            nr=dr;
            dr=r;
r=nr%dr;
}
            return(dr);
}


Out put
Enter three numbers : 45
81
81
Greatest common divisor is 9
Press any key to continue....




36.       Write a program to sum of the two integer values using Pointer?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int a,b,s=0;
            int *aptr,*bptr;
            clrscr();
            print(“\n Enter the integer number :”);
            scanf(“%d%d””, &a,&b);
            aptr=&a;
            bprt=&b;
            s=*aptr+*bprt;
            printf(“\nsum=%d”,s);
getch();
}

Output
Enter two integer numbers :
50
150
Sum=200




37.       Write a program to find the biggest number using Pointer?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int a,b,big;
            int *xptr,*yptr;
            clrscr();
            printf(“\n Enter twe integer numbers :”);
            scanf(“%d%d”,&a,&b);
            xptr=&a;
            yptr=&b;
            if(*xptr>*yptr)
            big=*xptr;
            else
            big=*yptr;
            printf(“\n Biggest no. is %d”, big);
getch();
}

Output

Enter two integer numbers : 89
116

Biggest no. is 116




38.       Write a program to read & display the details of the student using structure?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            struct student
{
            int rno;
            char sname[20]
            int tot;
}
};
struct student x;
clrscr();
printf(‘\n Enter the student roll no :”);
scanf(“%d”,&x.rno);
printf(“\n Enter the name of the student :”);
scanf(“%s”,&x.sname);
printf(“\n Enter the student marks :”);
scanf(“%d”,&x.tol);
printf(“\n\n Details of the students :\n”);
printf(“---------------------------“);
printf(“\n roll no:%d”,x.rno);
printf(“\n student name : %s”,x.sname);
printf(“\nMarks: %d”,x.tot);
getch();
}

Output

Enter the student roll no : 51
Enter the name of the student: Danish
Enter the student marks : 75

Details of the students:
---------------------------
roll no: 51
student name : Danish
Marks : 75




39.       Write a program to sort that arranges of the element of array in ascending order?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
int i,x[50],n;
void sort (intx[],int n);
clrscr();
printf(“\n How may values :”);
scanf(“%d”,&n);
printf(\n Enter the list of the values \n”);
for(i=0;i<n;i++)
scanf(“%d”,&x[i]);
sort(x,n);
for(i=0;i<n,i++)
printf(“%5d”,x[i]);
getch();
}
void sort(int x[ ],int n)
{
            int i,j,temp;
            for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(x[i]>x[j];
x[i]=s[j];
x[j]=temp;
}
}

Output

How may values : 6

Enter the list of the values
3 6 7 8 2 9

2          3          6          7          8          9



 
40.       Write a program to count the numbers of vowels present in the sentence?

Solution

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char st[80],ch;
int count=0,i;
clrscr();
printf(“\n Enter the sentences :\n”);
gets(st)
switch(st[i])
{
            case ‘A’:
            case ‘E’:
            case ‘I’:
            case ‘O’:
            case ‘U’:
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
count++;
break;
}
printf(“\n%d Vowels are present in the sentences”, count);
getch();
}

Output

Enter the sentences : Comm IT Career Academy

8 Vowels are present in the sentences

 


41.       Write a program to convert a line in the lowercase to uppercase?

Solution

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
            int i;
            char st[200],c;
            clrscr();
            printf(“\n Enter the string in a line:”)
            gets(st);
for(i=0;i<strlen(st);i++)
if(st[i]>=97 & &st[i]<=112)
st[i]=st[i]=32;
printf(“\n The string line in uppercase case: \n%s”,st);
getch();
}

Output

Enter the string in a line: i m the best dancer...

The string line in uppercase case: I M THE BEST DANCER...




42.       Write a program to read a list of test marks of 50 students. Calculate the mean of marks and print a list of marks greater then mean?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int x[50],n,i,sum;
            float mean;
            clrscr();
            printf(“\n How may student:”);
            scanf(“%d”, &n);
            printf(“\n Enter the marks:”);
            for(i=0;i<n;i++)
            scanf(“%d”,&x[i]);
            sum=0;
            for(i=0;i<n;i++)
            sum=sum+x[i];
            mean=(float)sum/n;
            printf(“\n mean=%6.2f”, mean);
            printf(“\n\n marks greater than mean :”);
            for(i=0;i<n;i++)
            if(x[i]>mean)
            printf(“\n%d”,x[i]);
getch();
}

Output

How may student: 5

Enter the marks :
76
65
87
78
56

mean=72.40

marks greater than mean :
76
87
78




43.       Write a function that’ll swap the value of 2 integer variables passed as argument using Pointer?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            int  a=2,b=5;
            void temp(int *x,int *y);
            clrscr();
            printf(“\n\n\t Before Exchange”);
            printf(“\n\t-----------------------------“);
            printf(“\n Value of a=%d and b=%d”, a,b);
            temp(&a,&b);
            printf(“\n\n\t After Exchange”);
            getch();
}
void temp (int *x, int *y)
{
            int tmp;
            tmp=*x;
            *x=*y;
            *y=tmp;
printf(“\n\n Inside the function a=%d and b=%d”, *x,*y);
            }

Output

Before Exchange
----------------
Value of a=2 and b=5

Inside the function a=5 and b=2

After Exchange
----------------
Value of a=5 and b=2


            
 
44.       Declare a student of a student with details like roll no., sname and total mark. Using this declare an array with 50 elements. WAP to read details of n students and print the list of students who have scored 15 marks & above...


Solution

#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
            int rno;
            char sname[10];
            int marks;
};
            struct student x[50];
            clrscr();
            int n,i;
            printf(“\n Enter the number of students:”);
            scanf(“%d”,&n);
            for(i=0; i<n;i++)
{
            printf(“\n Enter the %d th student roll number:”,i+1);
            scanf(“%d”, &x[i].rno);
            printf(“\n Enter the %d th student name:”,i+1);
            scanf(“%s”,&x[i].sname);
            printf(“\n Enter the %dth student’s marks:”,i+1);
            scanf(“%d”, &x[i].narks);
}
printf(“\n The list of student who have scored 75 marks and above...”)
printf(“\n\n Details of the students:\n”);
printf(“----------------------“);
for(i=0li<n;i++)
{          
            If(x[i].marks>=75)
{
            printf(“\n Roll number of %dth student: %d”,i+1,x[i].rno);
            printf(“\n Name of %dth student: %s”, i+1,x[i].sname);
            printf(“\n Marks of %dth student: %d”,i+1,x[i].marks);
printf(“\n”);
}
}
getch();
}



Output

Enter the number of students: 3
Enter the 1th student roll number: 5
Enter the 1th student name: Sagar
Enter the 1th student’s marks: 90

Enter the 2th student roll number: 8
Enter the 2th student name: Amit
Enter the 2th student’s marks: 80

Enter the 3th student roll number: 15
Enter the 3th student name: Angel
Enter the 3th student’s marks: 60


The list of student who have scored 75 marks and above...
Details of the students:
-----------------------------------
Roll number of 1th student: 5
Name of 1th student: Sagar
Marks of 1th student: 90

Roll number of 1th student: 8
Name of 1th student: Amit
Marks of 1th student: 80

































 
45.       Define a structure with the following 3 members, rollno, name, & total marks of a student. Write a C program to read a display the details of student?

Solution

#include<stdio.h>
#include<conio.h>
void main()
{
            Struct student
{
int rno;
            char sname[10];
            int marks;
};
struct student x;
clrscr();
printf(“\n Enter the student roll number:”);
scanf(“%d”,&x.rno);
printf(“\n Enter the student name:”);
scanf(“%s”,&x.sname);
printf(“\n Enter th student’s marks:”);
scanf(“%d”,&x.marks);
printf(“\n\n Details of the student:\n”);
printf(“---------------------------“);
printf(“\n Roll number:%d”,x.rno);
printf(“\n Name:%s”,x.sname);
printf(“\n Marks:%d”,x.marks);
getch();
}

Output

Enter the student roll number: 00512002011

Enter the student name: Hrithik

Enter the student’s marks : 95

Details of the student:
---------------------------
Roll number: 00512002011
Name: Hrithik
Marks: 95

3 comments:

FEEDBACK

Name

Email *

Message *