0% found this document useful (0 votes)
379 views

GE6161

The document contains 20 C programming questions and their solutions. The questions cover a range of topics including finding the sum and reverse of digits in a number, checking if a number is a palindrome, generating Fibonacci series, manipulating arrays, matrices operations, string manipulation, and sorting. The full programs for each question are provided with comments explaining the logic.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
379 views

GE6161

The document contains 20 C programming questions and their solutions. The questions cover a range of topics including finding the sum and reverse of digits in a number, checking if a number is a palindrome, generating Fibonacci series, manipulating arrays, matrices operations, string manipulation, and sorting. The full programs for each question are provided with comments explaining the logic.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

1. Write a C program to find the sum of digits of a number. #include<stdio.h> #include<conio.

h> void main() { int n,r,sum=0; clrscr(); printf("Enter the number:"); scanf("%d",&n); while(n!=0) { r=n%10; sum=sum +r; n=n/10; } printf ("\n The Sum of digits is %d", sum); getch(); } 2. Write a C program to reverse the digits of a number. #include<stdio.h> #include<conio.h> void main() { int n,r,sum=0; clrscr(); printf("Enter the number:\n"); scanf("%d",&n); while(n!=0) { r=n%10; n=n/10; sum=sum*10+r; } printf("\nThe reverse is %d",sum); getch(); } 3. Write a C program to find the largest digit of a number. #include<stdio.h> #include<conio.h>

void main() { int n,r,large=-1; clrscr(); printf("Enter the number:\n"); scanf("%d",&n); while(n!=0) { r=n%10; if(r>large) { large=r; } n=n/10; } printf("\nThe Largest digit is %d",large); getch(); } 4. Write a C program to check whether the number and its reverse are same. (Palindrome number) #include<stdio.h> #include<conio.h> void main() { int n,r,a,sum=0; clrscr(); printf("Enter the number:\n"); scanf("%d",&n); a=n; while(n!=0) { r=n%10; n=n/10; sum=sum*10+r; } printf("\nThe given number is %d",a); printf("\nThe reverse is %d",sum); if(a==sum) { printf("\nThe entered number and reverse are same\n"); } else

{ printf("\nThe entered number and reverse are not same\n"); } getch(); } 5. Write a C program to check whether the given number is Armstrong or not. #include<stdio.h> #include<conio.h> void main() { int n,a,r,sum=0; clrscr(); printf("Enter the number."); scanf("%d",&n); a=n; while(a>0) { r=a%10; sum+=r*r*r; a=a/10; } if(sum==n) { printf("\nThe number %d is armstrong",n); } else { printf("\nThe number %d is not armstrong",n); } getch(); } 6. Write a C program to find the sum of odd-positioned digits and even positioned digits of a number separately. #include<stdio.h> #include<conio.h> void main() { int n,r,count=0,odd=0,even=0;

clrscr(); printf("Enter the number:\n"); scanf("%d",&n); while(n!=0) { r=n%10; count=count+1; if(count%2==0) { even=even+r; } else { odd=odd+r; } n=n/10; } printf("\nThe sum of odd positioned digits is %d",odd); printf("\nThe sum of even positioned digits is %d",even); getch(); } 7. Write a C program to find the second highest number from a set of numbers. #include<stdio.h> #include<conio.h> void main() { int list[20],n,i,firstlarge,seclarge,num; clrscr(); printf("\nEnter the size of the list\n"); scanf("%d",&n); printf("\nEnter the elements one by one\n"); scanf("%d",&num); firstlarge=num; seclarge=-9999; for(i=1;i<n;i++) { scanf("%d",&num); if(firstlarge<num) { seclarge=firstlarge;

firstlarge=num; } else { if(seclarge<num) seclarge=num; } } printf("\nSecond Large=%d",seclarge); getch(); } 8. Write a c program to generate Fibonacci series. #include<stdio.h> #include<conio.h> void main() { int n,count,a=0,b=1,c; clrscr(); printf("\nHow many terms u want to print\t"); scanf("%d",&n); printf("\nFibonacci series\n"); printf("%d\t%d\t",a,b); for(count=2;count<n;count++) { c=a+b; printf("%d\t",c); a=b; b=c; } getch(); } 9. Write a C program to generate numbers between 1 and 100 which are divisible by 2 and not divisible by 3 and 5. #include<stdio.h> #include<conio.h> void main() { int i; clrscr();

printf("\nThe numbers between 1 and 100 which are divisible by 2 and not divisible by 3 and 5 are "); for(i=1;i<100;i++) { if((i%2==0)&&(i%3!=0)&&(i%5!=0)) { printf("%d ",i); } } getch(); } 10. Write a C program to generate prime numbers between 50 and 100. #include <stdio.h> #include<conio.h> void main() { int n, i, flag=0; clrscr(); printf("\nThe Prime Nos Between 50 & 100 are:\n "); for(n=50;n<100;n++) { for(i=2;i<=n/2;i++) { if(n%i==0) { flag=1; break; } } if (flag==0) { printf("%d ",n); } flag=0; } getch(); } 11. Write a C program to count the number of times a digit is present in a number.

#include<stdio.h> #include<conio.h> void main() { int n,r,digit,count=0; clrscr(); printf("Enter the number:\n"); scanf("%d",&n); printf("Enter the digit u want to count:\n"); scanf("%d",&digit); while(n!=0) { r=n%10; if(r==digit) { count=count+1; } n=n/10; } printf("\n%d times the digit is present in the given number",count); getch(); } 12. Write a C program to interchange the elements of an array with the elements of another array without using the third array. #include<stdio.h> #include<conio.h> void main() { int a[20],b[20],i,n; clrscr(); printf("Enter the number of elements(Max 20)"); scanf("%d",&n); printf("\nEnter the elements of first array one by one"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\nEnter the elements of second array one by one"); for(i=0;i<n;i++) { scanf("%d",&b[i]);

} printf("\nBefore Swapping\n"); printf("\nElements of Array 1: "); for(i=0;i<n;i++) { printf("%d ",a[i]); } printf("\nElements of Array 2: "); for(i=0;i<n;i++) { printf("%d ",b[i]); } for(i=0;i<n;i++) { a[i]=a[i]+b[i]; b[i]=a[i]-b[i]; a[i]=a[i]-b[i]; } printf("\nAfter Swapping\n"); printf("\nElements of Array 1: "); for(i=0;i<n;i++) { printf("%d ",a[i]); } printf("\nElements of Array 2: "); for(i=0;i<n;i++) { printf("%d ",b[i]); } getch(); } 13. Write a C program to get a line of text and count the number of vowels in the text. #include<stdio.h> #include<conio.h> #include<string.h> void main() { int count=0,i,n; char text[100]; clrscr();

printf("\nEnter the line of text"); gets(text); n=strlen(text); for(i=0;i<n;i++) { switch(text[i]) { case 'A': case 'a': case 'E': case 'e': case 'I': case 'i': case 'O': case 'o': case 'U': case 'u': count=count+1; break; } } printf("\n The number of vowels in the given text is %d", count); getch(); } 14. Write a C program to find the product of two matrices. #include<stdio.h> #include<conio.h> void main() { int a[10][10],b[10][10],i,j,k,m1,n1,m2,n2,c[10][10]={0}; clrscr(); printf("\nEnter the order of 1st matrix \n"); scanf("%d%d",&m1,&n1); printf("\nEnter the elements of 1st matrix\n"); for(i=0;i<m1;i++) { for(j=0;j<n1;j++) { scanf("%d",&a[i][j]); } }

do { printf("\nEnter the order of 2nd matrix \n"); scanf("%d%d",&m2,&n2); }while(n1!=m2); printf("\nEnter the elements of 2nd matrix\n"); for(i=0;i<m2;i++) { for(j=0;j<n2;j++) { scanf("%d",&b[i][j]); } } printf("\nThe elements of 1st matrix\n"); for(i=0;i<m1;i++) { for(j=0;j<n1;j++) { printf("%d\t",a[i][j]); } printf("\n"); } printf("\nThe elements of 2nd matrix\n"); for(i=0;i<m2;i++) { for(j=0;j<n2;j++) { printf("%d\t",b[i][j]); } printf("\n"); } for(i=0;i<m1;i++) { for(j=0;j<n2;j++) { for(k=0;k<n1;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } printf("\nThe resultant matrix\n"); for(i=0;i<m1;i++)

{ for(j=0;j<n2;j++) { printf("%d\t",c[i][j]); } printf("\n"); } getch(); } 15. Write a C program to find the sum and difference of two matrices. #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],c[5][5],i,j,m,n; clrscr(); printf("\nEnter the order of matrices\n"); scanf("%d%d",&m,&n); printf("\nEnter the elements of 1st matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("\nEnter the elements of 2nd matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&b[i][j]); } } printf("\nThe elements of 1st matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",a[i][j]); }

printf("\n"); } printf("\nThe elements of 2nd matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",b[i][j]); } printf("\n"); } for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf("\nThe sum of two matrices is\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",c[i][j]); } printf("\n"); } for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=a[i][j]-b[i][j]; } } printf("\nThe difference of two matrices is\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",c[i][j]); } printf("\n"); }

getch(); } 16. Write a C program to get a matrix of order 3X3 and display a matrix of order 4X4 with the fourth row and column as the sum of rows and columns respectively. #include<stdio.h> #include<conio.h> void main() { int a[4][4],i,j; clrscr(); printf("\nEnter the elements of input matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\nThe elements of input matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } printf("\n"); } for(i=0;i<4;i++) { for(j=0;j<4;j++) { a[i][3]=a[i][0]+a[i][1]+a[i][2]; a[3][j]=a[0][j]+a[1][j]+a[2][j]; } } printf("\nThe elements of resultant matrix\n"); for(i=0;i<4;i++) { for(j=0;j<4;j++)

{ printf("%d\t",a[i][j]); } printf("\n"); } getch(); } 17. Write a C program to arrange the set of numbers in descending order. #include<stdio.h> #include<conio.h> void main() { int list[20],n,i,j,temp; clrscr(); printf("\nEnter the number of elements (max 20)\n"); scanf("%d",&n); printf("\nEnter the elements\n"); for(i=0;i<n;i++) scanf("%d",&list[i]); printf("\nB4 sorting the elements are:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); for(i=1;i<n;i++) { for(j=0;j<n-i;j++) { if(list[j]<list[j+1]) { temp=list[j]; list[j]=list[j+1]; list[j+1]=temp; } } } printf("\nAfter sorting the elements in descending order are:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); getch(); }

18. Write a function to find the product of two values without using * operator. #include<conio.h> #include<stdio.h> void main() { int a,b,i,product=0; clrscr(); printf("Enter the 1st number: "); scanf("%d",&a); printf("Enter the 2nd number: "); scanf("%d",&b); for(i=1;i<=b;i++) { product=product+a; } printf("\n\n\nProduct of %d and %d is %d",a,b,product); getch(); } 19. Write a C program to get a line of text and count the number of words in the text. #include <stdio.h> #include<conio.h> void main() { char str[200]; int count = 0, i; clrscr(); printf("\nEnter the string\n"); scanf("%[^\n]s", str); for (i = 0;str[i] !='\0';i++) { if (str[i] ==' ') count=count+1; } printf("\nNumber of words in the given string are: %d\n", count +1); getch(); }

20. Write a C program to arrange the digits of a number in ascending order. #include<stdio.h> #include<conio.h> void bubblesort(int list[],int no); void main() { int n,r,a[10],i=0,j; clrscr(); printf("\nEnter the number:"); scanf("%d",&n); while(n!=0) { r=n%10; a[i]=r; n=n/10; i++; } bubblesort(a,i); printf("\nAfter sorting the digits the number is: "); for(j=0;j<i;j++) printf("%d",a[j]); getch(); } void bubblesort(int list[],int no) { int i,j,temp; for(i=1;i<no;i++) { for(j=0;j<no-i;j++) { if(list[j]>list[j+1]) { temp=list[j]; list[j]=list[j+1]; list[j+1]=temp; } } } } 21. Write a C program to a) Find the biggest of given three numbers.

b) Check whether the given year is leap year or not. #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int a,b,c,year,ch; clrscr(); do { printf("\nMenu"); printf("\n1.Biggest of 3 Numbers\n2.Leap year or Not\n3.exit"); printf("\nEnter ur choice"); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter 3 nos\n"); scanf("%d%d%d",&a,&b,&c); if(a>b&&a>c) { printf("\n %d is biggest",a); } else if(b>a&&b>c) { printf("\n %d is biggest",b); } else { printf("\n %d is biggest",c); } break; case 2: printf("\nEnter the year\t"); scanf("%d",&year); if(((year%4==0)&&(year%100!=0))||(year%400==0)) { printf("%d year is a leap year",year); } else { printf("%d year is not a leap year",year);

} break; case 3: exit(0); default: printf("\nInvalid Input"); } }while(ch!=3); getch(); } 22. Write a C program to (i) find whether the given number is even or odd. (ii) Find the square root of a number. #include<stdio.h> #include<conio.h> #include<stdlib.h> //for exit() #include<math> //for sqrt() void main() { int n,ch; clrscr(); do { printf("\nMenu"); printf("\n1.Odd or Even\n2.Square Root\n3.exit"); printf("\nEnter ur choice"); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter a number\n"); scanf("%d",&n); if(n%2==0) { printf("\nThe number %d is even",n); } else { printf("\nThe number %d is odd",n); } break; case 2:

printf("\nEnter the number\t"); scanf("%d",&n); printf("\nthe square root of %d is %f",n,sqrt(n)); break; case 3: exit(0); default: printf("\nInvalid Input"); } }while(ch!=3); getch(); }

23. Write a C program to (i) check whether the given number is Armstrong or not. (ii) to reverse the digits of a given number. #include<stdio.h> #include<conio.h> void main() { int a,n,r,sum=0,rev=0; clrscr(); printf("Enter the number."); scanf("%d",&n); a=n; while(a!=0) { r=a%10; sum=sum+r*r*r; rev=rev*10+r; a=a/10; } if(sum==n) { printf("\nThe number %d is armstrong",n); } else { printf("\nThe number %d is not armstrong",n); } printf("\nThe reverse of %d is %d",n,rev); getch();

} 24. Write a C program to check the given name is palindrome or not without using string function. #include<stdio.h> #include<conio.h> void main() { int len,i,j,count=0; char str[15]; clrscr(); printf("\n Enter the string:"); scanf("%s",str); for(i=0;str[i]!='\0';i++) { count=count+1; } len=count; for(i=0,j=len-1;i<len/2;i++,j--) { if(str[i]!=str[j]) { printf("\nThe String is not a palindrome"); getch(); exit(0); } } printf("\nThe String is a palindrome"); getch(); } 25. Write a C program to swap two numbers without using third variable using function concept. #include<stdio.h> #include<conio.h> void swap(); int num1,num2; void main( ) { clrscr(); printf("\nEnter the first number : ");

scanf("%d",&num1); printf("\nEnter the Second number : "); scanf("%d",&num2); printf("\nBefore Swapping\n"); printf("\nFirst number : %d",num1); printf("\nSecond number : %d\n",num2); swap() ; getch(); } void swap() { num1=num1+num2; num2=num1-num2; num1=num1-num2; printf("\nAfter Swapping\n"); printf("\nFirst number : %d",num1); printf("\nSecond number : %d\n",num2); } 26. Write a C program to find the factorial of given number using recursive function. #include<stdio.h> #include<conio.h> int fact(int); void main() { int num,f; clrscr(); printf("\nEnter a number: "); scanf("%d",&num); f=fact(num); printf("\nFactorial of %d is: %d",num,f); getch(); } int fact(int n) { if(n==1) return 1; else return(n*fact(n-1)); }

27. Write a C program to sort the given number in ascending order using arrays. #include<stdio.h> #include<conio.h> void main() { int list[20],n,i,j,temp; clrscr(); printf("\nEnter the number of elements (max 20)\n"); scanf("%d",&n); printf("\nEnter the elements\n"); for(i=0;i<n;i++) scanf("%d",&list[i]); printf("\nB4 sorting the elemrents are:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); for(i=1;i<n;i++) { for(j=0;j<n-i;j++) { if(list[j]>list[j+1]) { temp=list[j]; list[j]=list[j+1]; list[j+1]=temp; } } } printf("\nAfter sorting the elemrents are:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); getch(); } 28. Write a C program to transpose the given matrix. #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],i,j,m,n; clrscr();

printf("\nEnter the order of matrix\n"); scanf("%d%d",&m,&n); printf("\nEnter the elements one by one\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("\nThe elements of input matrix are\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",a[i][j]); } printf("\n"); } for(i=0;i<m;i++) { for(j=0;j<n;j++) { b[i][j]=a[j][i]; } } printf("\nThe transposed matrix is\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",b[i][j]); } printf("\n"); } getch(); }

29. Write a C program to input n numbers using a one dimensional array and find the sum of odd and even positions separately. #include<stdio.h>

#include<conio.h> void main() { int a[10],n,i,oddsum=0,evensum=0; clrscr(); printf("\nENTER THE NUMBER OF ELEMENTS:\t"); scanf("%d",&n); printf("\nENTER THE ELEMENTS ONE BY ONE\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if(i%2==0) { evensum=evensum+a[i]; } else { oddsum=oddsum+a[i]; } } printf("\nSUM OF ELEMENTS AT ODD POSITIONS IS %d",oddsum); printf("\nSUM OF ELEMENTS AT EVEN POSITIONS IS %d",evensum); getch(); } 30. Write a C program to generate the employee payroll using structures. #include<stdio.h> #include<conio.h> struct employee { char name[20]; int empno; int basicpay; int da; int ta; int hra; int cca; int pf;

}; void main() { struct employee payroll; int grosspay,netpay; clrscr(); printf("\nEnter the employee details"); printf("\nEmployee Number:\t"); scanf("%d",&payroll.empno); printf("\nEmployee Name:\t"); scanf("%s",payroll.name); printf("\nEnter Basic pay:\t"); scanf("%d",&payroll.basicpay); printf("\nEnter DA:\t"); scanf("%d",&payroll.da); printf("\nEnter HRA:\t"); scanf("%d",&payroll.hra); printf("\nEnter TA:\t"); scanf("%d",&payroll.ta); printf("\nEnter PF:\t"); scanf("%d",&payroll.pf); printf("\nEnter CCA:\t"); scanf("%d",&payroll.cca); grosspay=payroll.basicpay+payroll.da+payroll.ta+payroll.hra+payroll.cca; netpay=grosspay-payroll.pf; printf("\nEmployee Payroll\n"); printf("\nEmployee Number: %d",payroll.empno); printf("\nEmployee Name: %s",payroll.name); printf("\nBasic Pay: %d",payroll.basicpay); printf("\nHRA: %d",payroll.hra); printf("\nDA: %d",payroll.da); printf("\nTA: %d",payroll.ta); printf("\nCCA: %d",payroll.cca); printf("\nPF: %d",payroll.pf); printf("\nNet pay: %d",netpay); getch(); } 31. Write a C program to generate student mark sheets with subject details and the grades using Structure. #include<stdio.h> #include<conio.h>

#define max 10 int gradepoint(char x); struct student { char name[max]; int reg; int c[max]; char g[max]; char s[max][max]; float gpa; }stud[max]; void main() { int n,ns,i,j,sum=0,credit_total=0,x; clrscr(); printf("\nEnter the no.of students\t"); scanf("%d",&n); for(i=0;i<n;i++) { stud[i].gpa=0; printf("\nEnter the name of student %d\t",i+1); scanf("%s",stud[i].name); printf("\nEnter the Register Number of %s\t",stud[i].name); scanf("%d",&stud[i].reg); printf("\nEnter the no.of subjects\t"); scanf("%d",&ns); for(j=0;j<ns;j++) { printf("\nEnter the name of subject %d\t",j+1); scanf("%s",stud[i].s[j]); printf("\nEnter the Credits of Subject %d\t",j+1); scanf("%d",&stud[i].c[j]); printf("\nEnter the grade of Subject %d\t",j+1); scanf("%s",&stud[i].g[j]); } for(j=0;j<ns;j++) { if((x=gradepoint(stud[i].g[j]))!=0) { sum=sum+(stud[i].c[j]*x); credit_total=credit_total+stud[i].c[j]; } }

stud[i].gpa=(float)sum/credit_total; } for(i=0;i<n;i++) { printf("\n\t\t\tStudName\tRegNo\n"); printf("\t\t\t%s\t%d\n",stud[i].name,stud[i].reg); printf("\n\t\t\tSubName\tCredits\tGrade\n"); for(j=0;j<ns;j++) { printf("\t\t\t%s\t%d\t%c\n",stud[i].s[j],stud[i].c[j],stud[i].g[j]); } printf("\n\t\t\tGPA is %.2f\n",stud[i].gpa); } getch(); } int gradepoint(char x) { int gp; switch(x) { case 'S': case 's': gp=10; break; case 'A': case 'a': gp=9; break; case 'B': case 'b': gp=8; break; case 'C': case 'c': gp=7; break; case 'D': case 'd': gp=6; break; case 'E': case 'e': gp=5;

break; case 'U': case 'u': gp=0; break; } return gp; } 32. Write a function to arrange the numbers in decreasing order. Provide Input and Outputs only in the main method. #include<stdio.h> #include<conio.h> void bubblesort(int a[], int no); void main() { int list[20],n,i; clrscr(); printf("\nEnter the number of elements (max 20)\n"); scanf("%d",&n); printf("\nEnter the elements\n"); for(i=0;i<n;i++) scanf("%d",&list[i]); printf("\nB4 sorting the elemrents are:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); bubblesort(list, n); printf("\nAfter sorting the elemrents are:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); getch(); } void bubblesort(int a[], int no) { int i,j,temp; for(i=1;i<no;i++) { for(j=0;j<no-i;j++) { if(a[j]<a[j+1]) { temp=a[j];

a[j]=a[j+1]; a[j+1]=temp; } } } } 33. Write a C program to generate the first 50 Fibonacci numbers. #include<stdio.h> #include<conio.h> void main() { unsigned long int n,count,a=0,b=1,c; clrscr(); printf("\nFirst 50 numbers in the fibonacci series are\n"); printf("%lu %lu ",a,b); for(count=2;count<=50;count++) { c=a+b; printf("%lu\t",c); a=b; b=c; } getch(); } 34. Write a C program to print the pascal s triangle. Test your program and report the results obtained. #include <stdio.h> #include<conio.h> int factorial(int); void main() { int i,j,c,n; clrscr(); printf("\nEnter the number of rows you wish to print in pascal triangle\n"); scanf("%d",&n); for ( i = 0 ; i < n ; i++ ) { for (j= 0; j<= ( n - i - 2 ) ; j++ ) printf(" "); for( c = 0 ; c <= i ; c++ )

printf("%d ",factorial(i)/(factorial(c)*factorial(i-c))); printf("\n"); } getch(); } int factorial(int n) { int i,fact=1; for(i=1;i<=n;i++ ) fact=fact*i; return fact; } 35. Write a C program to find the smallest and largest of the given array. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { int a[10],n,i,small,big; clrscr(); printf("\nEnter the number of elements"); scanf("%d",&n); printf("\nEnter the elements one by one"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } big=small=a[0]; for(i=1;i<n;i++) { if(a[i]>big) big=a[i]; if(a[i]<small) small=a[i]; } printf("\nThe smallest number in the array is %d",small); printf("\nThe biggest number in the array is %d",big); getch(); }

36. Write a program to find the area and circumference of the circle. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> float area(float r); float circumference(float r); void main() { float r; clrscr(); printf("\nEnter the radius of a circle"); scanf("%f",&r); printf("\nArea=%f",area(r)); printf("\nCircumference=%f",circumference(r)); getch(); } float area(float r) { return 3.14*r*r; } float circumference(float r) { return 2*3.14*r; } 37. Write a program to find sum of Digits, Reverse and the given Number is Palindrome or not. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { int a,n,r,sum=0,rev=0,arm=0; clrscr(); printf("Enter the number."); scanf("%d",&n); a=n; while(a!=0) { r=a%10; arm=arm+r*r*r;

rev=rev*10+r; sum=sum+r; a=a/10; } if(arm==n) { printf("\nThe number %d is armstrong",n); } else { printf("\nThe number %d is not armstrong",n); } printf("\nThe reverse of %d is %d",n,rev); printf("\nthe sum of digits of %d is %d",n,sum); getch(); } 38. Write a program to find the string length and concatenation of string. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char str1[]="Saveetha ",str2[]="College"; int b; clrscr(); printf("\nString 1: "); puts(str1); printf("\nString 2: "); puts(str2); strcat(str1,str2); printf("\nConcatenated String: "); puts(str1); b=strlen(str1); printf("\nThe length of the new string is %d",b); getch(); } 39. Write a program to assigning values to the structures variables and retrieving values. Test your program and report the results obtained. #include<stdio.h>

#include<conio.h> struct student { char name[20]; int rollno,m1,m2,m3,m4,m5; float avg; }; void main() { struct student stud; clrscr(); printf("\nEnter student name: "); scanf("%s",stud.name); printf("\nEnter roll number: "); scanf("%d",&stud.rollno); printf("\nEnter the marks\n"); scanf("%d%d%d%d%d",&stud.m1,&stud.m2,&stud.m3,&stud.m4,&stud.m5); stud.avg=(stud.m1+stud.m2+stud.m3+stud.m4+stud.m5)/5.0; printf("\nStudent name is %s\n",stud.name); printf("\nStudent rollno %d\n",stud.rollno); printf("\nMarks1 %d\n",stud.m1); printf("\nMarks2 %d\n",stud.m2); printf("\nMarks3 %d\n",stud.m3); printf("\nMarks4 %d\n",stud.m4); printf("\nMarks5 %d\n",stud.m5); printf("\nAverage %0.2f\n",stud.avg); getch(); } 40. Write a C program to check the given number is prime or not. Test your program and report the results obtained. #include <stdio.h> #include<conio.h> void main() { int n, i, flag=0; clrscr(); printf("\nEnter a positive integer: "); scanf("%d",&n); for(i=2;i<=n/2;i++) {

printf("i=%d ",i); if(n%i==0) { flag=1; break; } } if (flag==0) printf("%d is a prime number.",n); else printf("%d is not a prime number.",n); getch(); }

41.Write a function program to search a given element from a set of values. #include<stdio.h> #include<conio.h> void main() { int list[20],n,val,i,pos=-1; clrscr(); printf("\t\t\tLINEAR SEARCH\n"); printf("\nEnter the size of the list\n"); scanf("%d",&n); printf("\nEnter the elements one by one\n"); for(i=0;i<n;i++) { scanf("%d",&list[i]); } printf("\nEnter the value to be searched\n"); scanf("%d",&val); for(i=0;i<n;i++) { if(val==list[i]) { pos=i; break; } } if(pos!=-1) printf("\nThe element found at %d location",pos); else

printf("\nSearch Failed\n"); getch(); } 42. Write a C program to simulate the calculator using Function. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> #include<stdlib.h> int add(int,int); int sub(int,int); int mul(int,int); int divide(int,int); void main() { int a,b,ch; clrscr(); printf("\nMenu Driven Calculator\n"); do { printf("\nMenu"); printf("\n1.Add\n2.Substract\n3.Multiply\n4.Divide\n5.Exit"); printf("\nEnter your choice"); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter two numbers"); scanf("%d%d",&a,&b); printf("\nThe sum is %d",add(a,b)); break; case 2: printf("\nEnter two numbers"); scanf("%d%d",&a,&b); printf("\nThe difference is %d",sub(a,b)); break; case 3: printf("\nEnter two numbers"); scanf("%d%d",&a,&b); printf("\nThe product is %d",mul(a,b)); break;

case 4: printf("\nEnter two numbers"); scanf("%d%d",&a,&b); printf("\nThe Quotient is %d",divide(a,b)); break; case 5: exit(0); default: printf("\nInvalid Input!!!Please Try Again!!!"); } }while(ch!=5); getch(); } int add(int x,int y) { return x+y; } int sub(int x,int y) { return x-y; } int mul(int x,int y) { return x*y; } int divide(int x,int y) { return x/y; } 43. Write a C program to find the roots of given quadratic equation. #include<stdio.h> #include<conio.h> #include<math.h> void main() { int a,b,c,d; float r1,r2; printf("\nEnter the coefficients a, b and c\t"); scanf("%d%d%d",&a,&b,&c); d=b*b-4*a*c; if(d>0) {

r1=(-b+sqrt(d))/(2*a); r2=(-b-sqrt(d))/(2*a); printf("Roots are real and unequal\n"); printf("\nRoots are: %f%f",r1,r2); } else if(d==0) { r1=-b/(2*a); printf("\nRoots are real and equal\n"); printf("\nRoots are %f %f",r1,r1); } else { printf("\nNo real roots; roots are imaginary"); } getch(); } 44. Write a C program to create a structure called employee with name, employee id, age, designation and salary as data members. Accept five employee details and display it. #include<stdio.h> #include<conio.h> struct employee { char name[20]; int empid; int age; char designation[20]; int salary; }; void main() { struct employee emp[5]; int i; printf("\nEnter employee details"); for(i=0;i<5;i++) { printf("\nEnter the details of employee: %d",i+1); printf("\nEnter employee name: "); scanf("%s",emp[i].name); printf("\nEnter employee id: "); scanf("%d",&emp[i].empid);

printf("\nEnter employee designation: "); scanf("%s",emp[i].designation); printf("\nEnter employee age: "); scanf("%d",&emp[i].age); printf("\nEnter employee salary: "); scanf("%d",&emp[i].salary); } printf("\n\t\t\tEmployee Details\n\n"); printf("\n\t\tName\tID\tDesignation\tAge\tSalary\n"); for(i=0;i<5;i++) { printf("\t\t%s\t%d\t%s\t%d\t%d\n",emp[i].name,emp[i].empid, emp[i].designation,emp[i].age,emp[i].salary); } getch(); } 45. Write a C program to evaluate the expression y = x + x2+........+xn by passing values to user defined function. Collect and display the values returned by the called function. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> #include<math.h> int sum(int,int); void main() { int x,n; printf("\nEnter the values of x and n"); scanf("%d%d",&x,&n); printf("\nSum is %d",sum(x,n)); getch(); } int sum(int a,int b) { if(b==1) return a; else return pow(a,b)+sum(a,(b-1)); }

46. Write a C program to accept a string in any case and convert it to another case. Test your program with at least three data and provide output. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char str[20]; clrscr(); printf("\nEnter a string in lowercase: "); scanf("%s",str); strupr(str); printf("\nThe sring in uppercase is %s",str); printf("\nEnter a string in uppercase: "); scanf("%s",str); strlwr(str); printf("\nThe sring in lowercase is %s",str); getch(); } 47. Write a C program to accept any single digit number and print it in words. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("\nEnter a single digit number"); scanf("%d",&n); switch(n) { case 0: printf("\nZero"); break; case 1: printf("\nOne"); break;

case 2: printf("\nTwo"); break; case 3: printf("\nThree"); break; case 4: printf("\nFour"); break; case 5: printf("\nFive"); break; case 6: printf("\nSix"); break; case 7: printf("\nSeven"); break; case 8: printf("\nEight"); break; case 9: printf("\nNine"); break; default: printf("\nEnter correct no and try again"); } getch(); } 48. Write a C program to accept a number and print mathematical table of the given number. Test your program with at least three data and provide output. #include<stdio.h> #include<conio.h> void main() { int n,i; clrscr(); printf("\nEnter the number"); scanf("%d",&n);

printf("The mathematical Table of given number is\n"); for(i=1;i<=25;i++) { printf("\n%2d * %d = %3d",i,n,i*n); } getch(); } 49. Write a C program to calculate the square of those numbers only whose least significant digit is 5. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { int n,i; clrscr(); printf("\nEnter the Limit "); scanf("%d",&n); for(i=5;i<=n;i++) { if(i%10==5) { printf(" \n Square of %d is %d",i , i*i); } } getch(); } 50. Write a C program to read the values of A,B,C through the keyboard. Add them and after addition check if it is in the range of 100 to 200 or not. Print separate message for each. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { int a,b,c,sum; clrscr(); printf("\nEnter three numbers: "); scanf("%d%d%d",&a,&b,&c); sum=a+b+c;

if(sum>=100&&sum<=200) { printf("\nThe sum %d is in the range from 100 t0 200",sum); } else { printf("\nThe sum %d is not in the range from 100 t0 200",sum); } getch(); } 51. Write a C program to count a character that appears in a given text for number of times using while loop. Test your program with at least three sets of data and provide the output. #include<stdio.h> #include<conio.h> void main() { char ch,str[100]; int i=0,count=0; clrscr(); printf("\nenter the string\n"); gets(str); printf("\nEnter the character u want to count\n"); scanf("%c",&ch); while(str[i]!='\0') { if(str[i]==ch) { count=count+1; } i++; } printf("\nThe no of occurences of %c in the string %s is %d",ch,str,count); getch(); } 52. Write a program to display all ASCII numbers and their equivalent characters, numbers and symbols using while loops. User should prompt every time to press Y or N. if user press Y display the next alphabet. Otherwise terminate the program. Test your program and report the results obtained.

#include<stdio.h> #include<conio.h> void main() { int num; char ch; clrscr(); printf("Printing ASCII values Table...\n\n"); num = 1; printf("\nValue:%d = ASCII Character:%c", num, num); num++; printf("\nDo u want to continue(y/n)"); ch=getche(); while(ch=='Y'||ch=='y') { printf("\nValue:%d = ASCII Character:%c", num, num); num++; printf("\nDo u want to continue(y/n)"); ch=getche(); } getch(); } 53. Write a C program to (i) Calculate the area of a circle (ii) Convert the C0 to F0. #include<stdio.h> #include<conio.h> void main () { float c, f, r; char ch; clrscr(); printf("Instructions:\n"); printf("Enter 'A' to find the area of circle:\n"); printf("Enter 'C' to convert Celsius to Farenheit:\n"); printf("\nEnter a character: "); scanf("%c",&ch); if (ch=='a' || ch=='a') { printf("Enter the radius: "); scanf("%f",&r);

printf("\nThe area is: %f",3.14*r*r); } if (ch=='c' || ch=='C') { printf ("Enter the value of Temperature in Celcius: "); scanf ("%f", &c); f = (1.8 * c) + 32; printf ("The value of Temperature in Fahreinheit is: %f", f); } getch(); } 54. Write a C program to get todays date as input and print the tomorrows date. #include<stdio.h> #include<conio.h> void main() { int dd,mm,yyyy,dd1,mm1,yyyy1; int nd[]={31,28,31,30,31,30,31,31,30,31,30,31}; clrscr(); printf("\nTodays date in the format(DD MM YYYY)\n"); scanf("%d%d%d",&dd,&mm,&yyyy); if(dd<nd[mm-1]) { dd1=dd+1; mm1=mm; yyyy1=yyyy; } else { if(dd==nd[mm-1]) { dd1=1; mm1=mm+1; if(mm1>12) { mm1=mm1-12; yyyy1=yyyy+1; } else { yyyy1=yyyy;

} } } printf("\nToday's date is %d/%d/%d\n", dd, mm, yyyy); printf("\nTmw's date is %d/%d/%d\n",dd1,mm1,yyyy1); getch(); } 55. Write a C program to create a structure called point with XC and YC as data members. Find the difference between two points. #include<stdio.h> #include<conio.h> struct point { int xc; int yc; }; void main() { struct point p1={5,8}, p2={2,3},p3; int x,y; clrscr(); p3.xc=p1.xc-p2.xc; p3.yc=p1.yc-p2.yc; printf("\nP1(%d,%d)\n",p1.xc,p1.yc); printf("\nP2(%d,%d)\n",p2.xc,p2.yc); printf("\nDifference is"); printf("\nP3(%d,%d)\n",p3.xc,p3.yc); getch(); } 56. Write a program to perform the following Display the question What is the unit of distance? Accept the answer If the answer is wrong display try again & continue to answer Otherwise, if it is correct display the message the answer is correct If the user gives the correct answer in first two attempts the program will terminate If the user fails to provide the correct answer in three attempts the program itself gives the answer.

Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { char ans[10],correctans[]="meter"; int attempt=0; do { printf("\nWhat is the unit of distance ?"); scanf("%s",ans); attempt=attempt+1; }while(strcmp(ans,correctans)!=0&&attempt!=3); if(attempt==3) printf("\nThe correct answer is \"Meter\""); getch(); } 57. Write a C Program to create a structure called Time with hour, minute and second as data members. Find the difference between two time values with valid time. #include<stdio.h> #include<conio.h> struct time { int hrs; int mins; int secs; }; void main() { struct time t1,t2,t3; clrscr(); printf("\nEnter time 1 in 24 hrs format(HH MM SS): "); scanf("%d%d%d",&t1.hrs,&t1.mins,&t1.secs); printf("\nEnter time 2 in 24 hrs format(HH MM SS): "); scanf("%d%d%d",&t2.hrs,&t2.mins,&t2.secs); t3.secs=t2.secs-t1.secs; if(t3.secs<0) {

t3.secs=t3.secs+60; t2.mins=t2.mins-1; } t3.mins=t2.mins-t1.mins; if(t3.mins<0) { t3.mins=t3.mins+60; t2.hrs=t2.hrs-1; } t3.hrs=t2.hrs-t1.hrs; printf("\nTime 1 is: %d : %d : %d",t1.hrs,t1.mins,t1.secs); printf("\nTime 2 is: %d : %d : %d",t2.hrs,t2.mins,t2.secs); printf("\nTime difference is: %d : %d : %d",t3.hrs,t3.mins,t3.secs); getch(); } 58. Write a C program to find the product of two n*n matrices by using functions. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void multiply(); void main() { //clrscr(); multiply(); getch(); } void multiply() { int a[10][10],b[10][10],i,j,k,n,c[10][10]={0}; printf("\nEnter the value of n \n"); scanf("%d",&n); printf("\nEnter the elements of 1st matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("\nEnter the elements of 2nd matrix\n"); for(i=0;i<n;i++)

{ for(j=0;j<n;j++) { scanf("%d",&b[i][j]); } } printf("\nThe elements of 1st matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d\t",a[i][j]); } printf("\n"); } printf("\nThe elements of 2nd matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d\t",b[i][j]); } printf("\n"); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { for(k=0;k<n;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } printf("\nThe resultant matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d\t",c[i][j]); } printf("\n"); }

} 59.Write a C program to arrange the given names in the alphabetical order using arrays. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char name[10][20],temp[20]; int i,j,n; clrscr(); printf("Enter the total number of names\n"); scanf("%d",&n); printf("\nEnter the names one by one.....\n"); for(i=0;i<n;i++) { scanf("%s",name[i]); } printf("\nNames in alphebetical order\n\n"); for(i=1;i<n;i++) { for(j=1;j<n;j++) { if((strcmp(name[j-1],name[j]))>0) { strcpy(temp,name[j-1]); strcpy(name[j-1],name[j]); strcpy(name[j],temp); } } } for(i=0;i<n;i++) printf("\t%d)%s\n",i+1,name[i]); getch(); } 60. Write a c program to find whether a square matrix is symmetric. Test your program and report the results obtained. #include<stdio.h>

#include<conio.h> #include<stdlib.h> void main() { int arr[10][10], arrT[10][10]; int i,j,n; clrscr(); printf("\nA symmetric matrix is a square matrix that is equal to its transpose.\n"); printf("\nEnter the no.of rows of square matrix\n"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("\nEnter the element arr[%d][%d] : ",i,j); scanf("%d",&arr[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { arrT[j][i] = arr[i][j]; } } printf("\nThe elements in Input matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",arr[i][j]); } printf("\n"); } printf("\nThe elements in Transposed matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",arrT[i][j]); } printf("\n");

} for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(arr[i][j] == arrT[i][j]) { continue; } else { printf("\nInput matrix is not a symmetric matrix."); getch(); exit(0); } } } printf("\nInput matrix is a symmetric matrix"); getch(); } 61. Write a C program to count the number of lines, vowels, consonants, words of a given text. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char str[80],ch; int i,c=0,s=0,v=0,w=1,len; clrscr(); printf("\n\tNo. of vowels, consonants, spaces and words"); printf("\n\t-------------------------------------------"); printf("\n\n\nEnter the String:\n"); gets(str); len=strlen(str); for(i=0;i<len;i++) { ch=str[i]; switch(toupper(ch)) { case 'A':

case 'E': case 'I': case 'O': case 'U': v++; break; case ' ': s++; break; default: c++; break; } if((str[i]==' ')&&(str[i-1] !=' ')) w++; } printf("\n\n Entered string is %s",str); printf("\n\n No. of Vowels:%d",v); printf("\n\n No. of Consonants:%d",c); printf("\n\n No. of Spaces:%d",s); printf("\n\n No. of Words:%d",w); getch(); } 62.Write a C program to create a structure called date with day, month and year as data member and find the difference between two dates. #include<stdio.h> #include<conio.h> struct date { int dd; int mm; int yyyy; }; void main() { struct date dob,c_date,diff; printf("\nEnter your Date of Birth(DD MM YYYY)\n"); scanf("%d%d%d",&dob.dd,&dob.mm,&dob.yyyy); printf("\nEnter Current Date (DD MM YYYY)"); scanf("%d%d%d",&c_date.dd,&c_date.mm,&c_date.yyyy);

if(c_date.dd>=dob.dd) diff.dd = c_date.dd-dob.dd; else { c_date.dd+=30; c_date.mm-=1; diff.dd = c_date.dd-dob.dd; } if(c_date.mm>=dob.mm) diff.mm = c_date.mm-dob.mm; else { c_date.mm+=12; c_date.yyyy-=1; diff.mm = c_date.dd-dob.mm; } diff.yyyy = c_date.yyyy-dob.yyyy; printf("\nYour age is: %d years %d months and %d days\n",diff.yyyy,diff.mm,diff.dd); getch(); } 63. Write a C program to print the abbreviation for a given sentence. (American Standard Code for Information Interchange as ASCII) #include<stdio.h> #include<string.h> void main() { char str[100],len,i; clrscr(); printf("Enter any string\n(Format: American Standard Code for Information Interchange)\n"); gets(str); len=strlen(str); for(i=0;i<len;i++) { if(isupper(str[i])) printf("%c",(str[i])); } getch(); }

64. Write a C program to print all combinations of a 4-digit number. #include<stdio.h> #include<conio.h> void main() { int a,b,c,d; printf("The Combinations of a 4 digit number 1234 \n"); clrscr(); for(a=1; a<5; a++) { for(b=1; b<5; b++) { for(c=1; c<5; c++) { for(d=1; d<5; d++) { if(!(a==b || a==c || a==d || b==c || b==d || c==d)) printf("%d%d%d%d\n",a,b,c,d); } } } } getch(); } 65. Write a C program to print all the proper factors of an integer. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> void main() { int i,n; clrscr(); printf("\n enter the no.\n"); scanf("%d",&n); for(i=2;i<=n;i++) { if(n%i==0) { printf("%d ",i); n=n/i;i--;

} } getch(); }

66. Write a C program to find the largest element in a row and largest element in a column of a given matrix. #include<stdio.h> #include<conio.h> void main() { int a[5][5],rbig[5],cbig[5]; int i,j,m,n; clrscr(); printf("\nEnter the order of Input matrix\n"); scanf("%d%d",&m,&n); printf("\nEnter the elements of Input matrix one by one\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("\nElements of Input matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",a[i][j]); } printf("\n"); } for(i=0;i<m;i++) { rbig[i]=a[i][0],cbig[i]=a[0][i]; for(j=1;j<n;j++) { if(a[i][j]>rbig[i]) rbig[i]=a[i][j]; if(a[j][i]>cbig[i])

cbig[i]=a[j][i]; } printf("\n"); } printf("\tNo\tRowMax\tColMax\n"); for(i=0;i<n;i++) { printf("\t%d\t%d\t%d\n",i,rbig[i],cbig[i]); } getch(); } 67. Write a C program to find the sum of the following series (sine) x-x3/3!+x5/5!-x7/7!++xn/n! #include<stdio.h> #include<math.h> float factorial(int n); void main() { int i,n,j; float sum=0.0,x,nr,dr; printf("\nEnter the Value of x in radians(eg:3.14) \n"); scanf("%f",&x); printf("\nEnter the power of end term: \n"); scanf("%d",&n); j=1; for(i=1;i<=n;i+=2) { nr=pow(x,i)*j; dr=factorial(i); sum=sum+(nr/dr); j=-j; } printf("The Result of sine series is : %f\n",sum); } float factorial(int n) { int i; float fact=1; for(i=1;i<=n;i++) fact=fact*i; return fact;

} 68.Write a C program to find the sum of the following series (cosine series) 1-x2/2!+x4/4!-x6\6!+ #include<stdio.h> #include<conio.h> #include<math.h> float factorial(int n); void main() { int i,n,j; float sum=1.0,x,nr,dr; clrscr(); printf("\nEnter the Value of x in radians: \n"); scanf("%f",&x); printf("\nEnter the power of end term: \n"); scanf("%d",&n); j=-1; for(i=2;i<=n;i+=2) { nr=pow(x,i)*j; dr=factorial(i); sum=sum+(nr/dr); j=-j; } printf("The Result of sine series is : %f\n",sum); getch(); } float factorial(int n) { int i; float fact=1; for(i=1;i<=n;i++) fact=fact*i; return fact; } 69. Write a C program to find the sum of the following series -x+x3/3!-x5/5!+ #include<stdio.h> #include<math.h>

float factorial(int n); void main() { int i,n,j; float sum=0.0,x,nr,dr; clrscr(); printf("\nEnter the Value of x in radians: \n"); scanf("%f",&x); printf("\nEnter the power of end term: \n"); scanf("%d",&n); j=-1; for(i=1;i<=n;i+=2) { nr=pow(x,i)*j; dr=factorial(i); sum=sum+(nr/dr); j=-j; } printf("The Result of sine series is : %f\n",sum); getch(); } float factorial(int n) { int i; float fact=1; for(i=1;i<=n;i++) fact=fact*i; return fact; } 70. Write a C program to perform String operations like Concatenation, Compare etc without using builtin functions. #include<stdio.h> #include<conio.h> void main() { char a[100],b[50],dif; int i,j,len1=0,len2=0; clrscr(); printf("\n Enter String 1 : "); scanf("%s",a); printf("\n Enter String 2 : ");

scanf("%s",b); while(a[i]!='\0'||b[i]!='\0') { dif=(a[i]-b[i]); if(dif!=0) break; i++; } if(dif>0) { printf("\n%s comes after %s\n",a,b); } else if(dif<0) { printf("\n%s comes after %s\n",a,b); } else { printf("\nBoth the strings are same\n"); } for(i=0;a[i]!='\0';i++) len1=len1+1; for(j=0;b[j]!='\0';j++) len2=len2+1; printf("\nLength of String 1=%d ",len1); printf("\nLength of String 2=%d ",len2); for(i=len1,j=0;i<=len1+len2;i++,j++) a[i]=b[j]; printf("\nThe Concatenated string is %s .",a); getch(); } 71. Write a c program to remove the occurrence of the word from entered string. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char str[256], text[256], words[100][256]; int i, j, k, n, flag; clrscr();

i = j = k = 0; /* get the input string from the user */ printf("\nEnter your input string:"); gets(str); /* get the word that needs to be removed from i/p string */ printf("\nEnter the word you want to remove:"); gets(text); /* copying each and every word from the string */ while (str[i] !='\0') { if (str[i] ==' ') { words[j][k] ='\0'; k = 0; j++; } else { words[j][k++] = str[i]; } i++; } words[j][k] = '\0'; /* print all words except the word that needs to be removed */ for (i = 0; i <= j; i++) { if (strcmp(words[i], text) != 0) { printf("%s ", words[i]); } } printf("\n"); getch(); } 72. Construct the numeric pyramid with two sides having same numbers and the inner elements having different numbers. Test your program with at least five levels of data and provide the output.

#include <stdio.h> #include<conio.h> int factorial(int); void main() { int i,j,c,n; clrscr(); printf("\nEnter the number of rows you wish to print in numeric pyramid\n"); scanf("%d",&n); for ( i = 0 ; i < n ; i++ ) { for (j= 0; j<= ( n - i - 2 ) ; j++ ) printf(" "); for( c = 0 ; c <= i ; c++ ) printf("%d ",factorial(i)/(factorial(c)*factorial(i-c))); printf("\n"); } getch(); } int factorial(int n) { int i,fact=1; for(i=1;i<=n;i++ ) fact=fact*i; return fact; } 73. Write a C program to find row sum and column sum of a given matrix #include<stdio.h> #include<conio.h> void main() { int a[5][5],rowsum[5]={0},colsum[5]={0},i,j,m,n; clrscr(); printf("\nEnter the order of input matrix\n"); scanf("%d%d",&m,&n); printf("\nEnter the elements of input matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++)

{ scanf("%d",&a[i][j]); } } printf("\nThe elements of input matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d\t",a[i][j]); } printf("\n"); } for(i=0;i<m;i++) { for(j=0;j<n;j++) { rowsum[i]=rowsum[i]+a[i][j]; } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { colsum[i]=colsum[i]+a[j][i]; } } printf("\nRow No\tRow wise sum\n"); for(i=0;i<m;i++) printf("%d\t%d\n",i,rowsum[i]); printf("\nCol No\tColumn wise sum\n"); for(i=0;i<n;i++) printf("%d\t%d\n",i,colsum[i]); getch(); } 74.Write a C program to display the binary bits corresponding to the hexadecimal numbers from 0 to F and display them. Test your program and report the results obtained. #include <stdio.h> #include <math.h> #include <string.h>

int hex_binary(char hex[]); void main() { int binary[16][4]={ {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}}; int i,j,a,r; char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; clrscr(); for(i=1;i<16;i++) { a=i; j=3; while (a!=0) { r=(a%2); binary[i][j]=r; a=a/2; j--; } } printf("\n\t\tHex\tBinary\n"); for(i=0;i<16;i++) { printf("\t\t%c\t",hex[i]); for(j=0;j<4;j++) { printf("%d",binary[i][j]); } printf("\n"); } getch(); } 75.Write a C program to check the given matrix is triangular or not. Test your program and report the results obtained. [A triangular matrix is a special kind of square matrix. A square matrix is called lower triangular if all the entries above the main diagonal are zero. Similarly, a square matrix is called upper triangular if all the entries below the main diagonal are zero. A triangular matrix is one that is either lower triangular or upper triangular. A matrix that is both upper and lower triangular is called a diagonal matrix.]

#include<stdio.h> #include<conio.h> void main() { int a[10][10],i,j,n; int flag=0,flag1=0; clrscr(); printf("\nEnter the no.of rows of the Square Matrix\n"); scanf("%d",&n); printf("\nEnter the elements of input square matrix 1 by 1\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("\nThe elements of input square matrix:\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",a[i][j]); } printf("\n"); } /*upper triangular matrix*/ for(i=1;i<n;i++) { for(j=0;j<i;j++) { if(a[i][j]==0) continue; else { flag=1; break; } } } /*Lower triangular Matrix*/ for(i=0;i<n-2;i++) {

for(j=i+1;j<n;j++) { if(a[i][j]==0) continue; else { flag1=1; break; } } } if(flag==0&&flag1==0) printf("\nThe given square matrix is both upper triangular & lower triangular\n"); else if(flag==0) printf("\nUpper triangular matrix\n"); else if(flag1==0) printf("\nLower triangular matrix\n"); else printf("\nNot a triangular matrix"); getch(); } 76. Write a C program to find n C r using recursive function #include<stdio.h> #include<conio.h> int fact(int); void main() { int n,r,ncr; clrscr(); printf("\n enter n and r:"); scanf("%d%d",&n,&r); ncr=fact(n)/(fact(n-r)*fact(r)); printf("\n Binomial co-efficient : %d",ncr); getch(); } int fact(int x) { if(x==0||x==1) return 1; else

return(x*fact(x-1)); } 77.Write a C program to generate the following triangle. 1 123 12345 1234567 #include <stdio.h> #include<conio.h> void main() { int i,j,k,c,n,bs=0; clrscr(); printf("\nEnter the number of rows you wish to print in the triangle\n"); scanf("%d",&n); /* bs -> number of blank spaces. the following for loop is used to find the no.of blank spaces in the first line. */ for(i=1;i<=n;i++) { if(i==1) bs=0; else bs=bs+2; } k=1; //no of elements in first row for (i=1;i<=n;i++ ) { for (j= 0; j<bs ; j++ ) printf(" "); //to print blank spaces for( c=1; c<=k ; c++ ) printf("%d ",c); printf("\n"); k=k+2; //no of elements in each row increased by 2 except first row. //no.of blank spaces reduced by 2 in each row except first row bs=bs-2; } getch();

} 78.Write a C program to generate the following triangle. 5 55 555 5555 #include <stdio.h> #include<conio.h> void main() { int i,j,c,n,no; clrscr(); printf("\nEnter the element u want to print\n"); scanf("%d",&no); printf("\nEnter the number of rows you wish to print in the triangle\n"); scanf("%d",&n); for ( i = 0 ; i < n ; i++ ) { for (j= 0; j<= ( n - i - 2 ) ; j++ ) printf(" "); for( c = 0 ; c <= i ; c++ ) printf("%d ",no); printf("\n"); } getch(); } 79.Write a C program for Library using Structure including the details of four fields namely title, author pages and price. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> struct library { char title[25],author[20]; int pages; float price; int count; }; void main()

{ struct library book[5]; int n,i; char str[25]; clrscr(); printf("\nEnter the no.of Category\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter the details of Category %d\n",i+1); printf("\nEnter the title of the book \n"); scanf("%s",book[i].title); printf("\nEnter the author of the book\n"); scanf("%s",book[i].author); printf("\nEnter the no.of pages\n"); scanf("%d",&book[i].pages); printf("\nEnter the price\n"); scanf("%f",&book[i].price); printf("\nEnter the no.of copies\n"); scanf("%d",&book[i].count); } printf("\n\t\tBook Details\n"); printf("\nTitle\tauthor\tPages\tprice\tCount\n"); for(i=0;i<n;i++) { printf("%s\t%s\t%d\t%0.2f\t%d\n",book[i].title,book[i].author, book[i].pages,book[i].price,book[i].count); } printf("\nEnter the book title u want to search\n"); scanf("%s",str); printf("\nTitle\tauthor\tPages\tprice\tCount\n"); for(i=0;i<n;i++) { if(strcmp(book[i].title,str)==0) { printf("%s\t%s\t%d\t%0.2f\t%d\n",book[i].title, book[i].author,book[i].pages,book[i].price,book[i].count); break; } } getch();

} 80.Write a C program to find the GCD and LCM by using Euclids Algorithm. Test your program and report the results obtained. #include<stdio.h> #include<conio.h> int gcd(int a,int b); void main() { int num1,num2,lcm,gc; clrscr(); printf("Enter two numbers\n"); scanf("%d %d", &num1,&num2); if(num1>num2) { gc=gcd(num1,num2); } else { gc=gcd(num1,num2); } printf("\nGCD=%d",gc); lcm=num1*num2/gc; printf("\nLCM=%d",lcm); getch(); } int gcd(int a,int b) { int t; while(b!=0) { t=b; b=a%b; a=t; } return a; } 81.Write a C program to calculate and display total cost of 4 models of Pentium PC. Use the single dimensional array for PC codes their price and quantity available. Test your program and report the results obtained.

#include<stdio.h> #include<conio.h> void main() { int code[4], quantity[4]; float price[4],totalcost=0; int i; clrscr(); for(i=0;i<4;i++) { printf("\nEnter the details of Pentium%d",i+1); printf("\nEnter the PC code\n"); scanf("%d",&code[i]); printf("\nEnter the price\n"); scanf("%f",&price[i]); printf("\nEnter the quantity available\n"); scanf("%d",&quantity[i]); totalcost=totalcost+price[i]*quantity[i]; } printf("\nPC code\tPrice\tQuantity\n"); for(i=0;i<4;i++) { printf("%d\t%0.2f\t%d\n",code[i],price[i],quantity[i]); } printf("\ntotal cost is %0.2f",totalcost); getch(); } 82. Calculate the area of circle, rectangle and triangle depending upon the users choice using structures. Test your program with at least three sets of data and provide the output. #include<stdio.h> #include<conio.h> #include<math.h> #include<stdlib.h> struct circle { float radius; float area; }circ; struct rectangle {

float length; float breadth; float area; }rect; struct triangle { float base; float height; float area; }trian; void main() { int choice; clrscr(); do { printf("\n1.Area of circle"); printf("\n2.Area of rectangle"); printf("\n3.Area of triangle"); printf("\n4.Exit"); printf("\nEnter your choice\n"); scanf("%d",&choice); switch(choice) { case 1: printf("\nEnter the radius\n"); scanf("%f",&circ.radius); circ.area=3.14*pow(circ.radius,2); printf("\nArea of circle is %f",circ.area); break; case 2: printf("\nEnter the length and breadth of the rectangle\n"); scanf("%f%f",&rect.length,&rect.breadth); rect.area=rect.length*rect.breadth; printf("\nArea of rectangleis %f",rect.area); break; case 3: printf("\nEnter the base and height of right angled triangle\n"); scanf("%f%f",&trian.base,&trian.height); trian.area=(trian.base*trian.height)/2; printf("\nArea of rectangleis %f",trian.area);

break; case 4: exit(0); default: printf("\nInvalid input!Please try again!!!"); } }while(choice!=4); getch(); } 83. Write a C program to sort the elements using Quick Sort. #include<stdio.h> #include<conio.h> #define N 20 void partition(int key,int list[],int lb,int ub); void quicksort(int list[],int lb,int ub); void main() { int list[N]; int i,size,temp; clrscr(); printf("\nEnter the size of the list(<20)"); scanf("%d",&size); printf("\nEnter the elements one by one\n"); for(i=0;i<size;i++) { scanf("%d",&list[i]); } quicksort(list,0,size-1); printf("\nthe sorted list is......"); for(i=0;i<size;i++) { printf("%d ",list[i]); } getch(); } void quicksort(int list[],int lb,int ub) { int pivot; pivot=list[lb]; lb++; partition(pivot,list,lb,ub);

} void partition(int key,int list[],int lb,int ub) { int i,j,temp; i=lb; j=ub; while(i<=j) { while(list[i]<=key) i++; while(list[j]>key) j++; if(i<=j) { temp=list[i]; list[i]=list[j]; list[j]=temp; } } temp=list[j]; list[j]=list[lb-1]; list[lb-1]=temp; if(j>lb) quicksort(list,lb,j-1); if(j<ub) quicksort(list,j+1,ub); } 84. Write a C program to sort the given elements using Merge Sort. #include<stdio.h> #include<conio.h> #define N 20 void mergesort(int list[],int lb,int ub); void merge(int list[],int lb,int mid,int ub); void main() { int list[N]; int i,size; clrscr(); printf("\nEnter the size of the list(<20)"); scanf("%d",&size); printf("\nEnter the elements one by one\n");

for(i=0;i<size;i++) { scanf("%d",&list[i]); } mergesort(list,0,size-1); printf("\nthe sorted list is......"); for(i=0;i<size;i++) { printf("%d ",list[i]); } getch(); } void mergesort(int list[],int lb,int ub) { int mid; if(lb<ub) { mid=(lb+ub)/2; mergesort(list,lb,mid); mergesort(list,mid+1,ub); merge(list,lb,mid+1,ub); } } void merge(int list[],int lb,int mid,int ub) { int mergelist[20]; int ptr1,ptr2,ptr3,i; ptr1=lb; ptr2=mid; ptr3=lb; while((ptr1<mid)&&(ptr2<=ub)) { if(list[ptr1]<=list[ptr2]) { mergelist[ptr3]=list[ptr1]; ptr1++; ptr3++; } else { mergelist[ptr3]=list[ptr2]; ptr2++; ptr3++;

} } while(ptr1<mid) { mergelist[ptr3]=list[ptr1]; ptr1++; ptr3++; } while(ptr1<mid) { mergelist[ptr3]=list[ptr2]; ptr2++; ptr3++; } for(i=lb;i<ptr3;i++) { list[i]=mergelist[i]; } }

You might also like