1.Write a C program to find maximum and minimum of given set of numbers #include<stdio.h> int main() { int i, n, lar,sm, tot; printf ("Enter total number of elements \ n"); scanf ("%d", &tot); printf ("Enter first number \ n"); scanf ("%d", &n); lar = n; sm=n; for (i=1; i<= tot ; i++) { printf (" \ n Enter another number \ n"); scanf ("%d",&n); if (n>lar) lar=n; if (n<sm) sm=n; } printf (" \ n The larges t number is %d", lar); printf (" \ n The smallest number is %d", sm); return 0; } Output: Enter total number of elements 4 Enter first number 5 Enter another number 7 Enter another number 1 Enter another number 10 The largest number is 10 The smallest number is 1 2.Write a C Program to find roots of quadratic equation The standard form of a quadratic equation is: ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 0 The term b 2 - 4ac is known as the discriminant of a quadratic equation. The discriminant tells the nature of the roots. If discriminant is greater than 0, the roots are real and different. If discriminant is equal to 0, the roots are real and equal. If discriminant is less than 0, the roots are complex and different. #include <stdio.h> #include <math.h> int main() { double a, b, c, discriminant, root1, root2, real, imaginary; printf("Enter coefficients a, b and c: "); scanf("%lf %lf %lf",&a, &b, &c); discriminant = b*b - 4*a*c; // condition for real and different roots if (discriminant > 0) { // sqrt() function returns square root root1 = ( - b+sqrt(discriminant))/(2*a); root2 = ( - b - sqrt(discriminant))/(2*a); printf("root1 = %.2lf and root2 = %.2lf",root1 , root2); } //condition for real and equal roots else if (discriminant == 0) { root1 = root2 = - b/(2*a); printf("root1 = root2 = %.2lf;", root1); } // if roots are not real else { realPart = - b/(2*a); imaginaryPart = sqrt( - discriminant)/(2*a); printf("root1 = %.2lf+%.2lfi a nd root2 = %.2f - %.2fi", real, imaginary, real , imaginary ); } return 0; } Output Enter coefficients a, b and c: 2.3 4 5.6 Roots are: - 0.87+1.30i and - 0.87 - 1.30i 3. Write a C program to convert a decimal number to a binary number #include <stdio.h> int main() { long num, decimal_num, remainder, base = 1, binary = 0; printf("Enter a decimal integer \ n"); scanf("%ld", &nu m); decimal_num = num; while (num > 0) { remainder = num % 2; binary = binary + remainder * base; num = num / 2; base = base * 10; } printf("Input number is = % l d \ n", decimal_num); printf("Its binary equivalent is = %ld \ n", binary); } Output: Enter a decimal integer 10 Input number is = 10 Its binary equivalent is = 1010 Enter a decimal integer 10 Input number is = 10 Its binary equivalent is = 1010 4. Write a program in C to convert a decimal number to hexadecimal. Pictorial Presentation: #include <stdio.h> int main() { long int decn um ,rmd,q,dn=0,m,l; int i=1,j,tmp; char s; printf("Input any Decimal number: "); scanf("%ld",&decn um ); q = decn um ; for(l=q;l>0;l=l/16) { tmp = l % 16; if( tmp < 10) tmp =tmp + 48; else tmp = tmp + 55; dn=dn*100+tmp; } pr intf(" \ nThe equivalent Hexadecimal Number : "); for(m=dn;m>0;m=m/100) { s=m % 100; printf("%c",s); } return 0; } Output: Input any Decimal number: 79 The equivalent Hexadecimal Number : 4F 5. C program to Convert Decimal to Octal #include <stdio.h> int main() { long decima lnum, remainder, quotient; int octalNumber[100], i = 1, j; printf("Enter the decimal number: "); scanf("%ld", &decimalnum); quotient = decimalnum; while (quotient != 0) { octalNumber[i++] = quotient % 8; quotient = quotient / 8; } printf("Equivalent octal value of decimal no %d: ", decimalnum); for (j = i - 1; j > 0; j -- ) printf("%d", octalNumber[j]); return 0; } Output Enter a decimal number: 68 78 in decimal = 104 in octal Program Explanation 1. Take a decimal number as input and store it in the variable decimalnum. 2. Copy the variable decimalnum to the variable quotient. 3. Divide the variable quotient and obtain its remainder and quotient. Store the remainder in the array octalNu mber and override the variable quotient with the quotient obtained. 4. Repeat the step 3 until the quotient becomes zero. 5. When it becomes zero, print the array octalNumber in the reverse order to get the output. 6. Write a c program to Generating Pascal triangle #include <stdio.h> int factorial(int n) { int f; for(f = 1; n > 1; n -- ) f *= n; return f; } int ncr(int n,int r) { return factorial(n) / ( factorial(n - r) * factorial(r) ); } int main() { int n, i, j; n = 5; for(i = 0; i <= n; i++) { for(j = 0; j <= n - i; j++) printf(" "); for(j = 0; j <= i; j++) printf(" %3d", ncr(i, j)); printf(" \ n"); } return 0; } The output should look like this − 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 7. Write a C Program to Construct Pyramid of numbers #include<stdio.h> #include<conio.h> main() { int i,j,n; clrscr(); printf("enter n value \ n"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=n - 1;j>=i;j -- ) printf(" "); for(j=1;j<=i;j++) printf("%3d",i); for(j=i - 1;j>=1;j -- ) printf("%3d",i); printf(" \ n"); } getch(); } Output: enter n value 4 1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 8. Find the sum of sin (x) series /* Write a C program to find the sum of sin (x) series */ Logic: 1. First the computer reads the value of x and limit from the user. 2. Now convert x to radian value x=x*(3.1415 \ 180) 3. Then using for loop the value of sin(x) is calculated. 4. Finally the value of sin(x) is printed. 5. Program for sin(x) series in C #include <stdio.h> #include <math.h> int fac( int x) { int i,fac=1; for (i=1;i<=x;i++) fac=fac*i; return fac; } int main() { float x,Q,sum=0; i nt i,j,limit; printf("Enter the value of x of sinx series: "); scanf("%f",&x); printf("Enter the limit upto which you want to expand the series: "); scanf("%d",&limit); Q=x; x = x*(3.1415/180); for (i=1,j=1;i<=limit;i++,j=j+2) { if (i%2!=0) { sum=sum+pow(x,j)/fac(j); } else sum=sum - pow(x,j)/fac(j); } printf("Sin(%0.1f): %f",Q,sum); return 0; } Output Enter the value of x of sinx series: 40 Enter the limit upto which you want to expand the series: 5 Sin(40.0): 0.642772 9. Find the sum of cos(x) series /* Write a C program to find the sum of cos(x) series */ #include<stdio.h> #include<math.h> void main() { int n,x1,i,j; float x,sign,cosx,fact; printf("Enter the number of the terms in aseries \ n"); scanf("%d",&n ); printf("Enter the value of x(in degrees) \ n"); scanf("%f",&x); x1=x; x=x*(3.142/180.0); /* Degrees to radians*/ cosx=1; sign= - 1; for(i=2;i<=n;i=i+2) { fact=1; for(j=1;j<=i;j++) { fact=fact*j; } cosx=cosx+(pow(x,i)/fact)*sign; sign=sign*( - 1); } printf("Sum of the cosine series = %7.2f \ n",cosx); } Output Enter the number of the terms in aseries 5 Enter the value of x(in de grees) 60 Sum of the cosine series = 0.50 10. C program to find factorial of a number using recursion #include <stdio.h> int factorial (int n); int main() { int n; printf("Enter a positive integer: "); scanf("%d", &n); printf( "Factoria l of %d = % d", n, factorial (n)); return 0; } int factorial (int n) { if (n >= 1) return n* factorial (n - 1); else return 1; } Output Enter a positive integer: 6 Factorial of 6 = 720 11. C program to prin t fibonacii series till n terms using recursion #include <stdio.h> void getFibonacii( int a, int b, int n) { int sum; if (n>0) { sum=a+b; printf("%d ",sum); a=b; b=sum; getFibonacii(a,b,n - 1); } } int main() { int a,b,sum,n; int i; a=0; //first term b=1; //second term printf("Enter total number of terms: "); scanf("%d",&n); printf("Fibonacii series is : "); printf("%d \ t%d \ t",a,b); //print a and b as fir st and second terms of series getFibonacii(a,b,n - 2); //call function with (n - 2) terms printf(" \ n"); return 0; } Output Enter total number of terms: 5 Fibonacii se ries is : 0 1 1 2 3 12.gcd using recursion #include <stdio.h> int gc d(int, int); int main() { int a, b, result; printf("Enter the two numbers in descending order to find their GCD: "); scanf("%d%d", &a, &b); result = gcd(a, b); printf("The GCD of %d and %d is %d. \ n ", a, b, result); } int gcd(int a, int b) { while (a != b) { if (a > b) { return gcd(a - b, b); } else { return gcd(a, b - a); } } return a; } Output: Enter the two numbers in descending order to find their GCD: 100 70 The GCD of 100 and 70 is 10. 13.Write a C program for matrix addition using arrays #include <stdio.h> int main() { int m, n, c, d, first[10][10], second[10][10], sum[10][10]; printf("Enter the number of rows and columns of matrix \ n "); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix \ n "); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &first[c][d]); printf("Enter the elements of second matrix \ n "); for (c = 0; c < m; c++) for (d = 0 ; d < n; d++) scanf("%d", &second[c][d]); printf("Sum of entered matrices: - \ n "); for (c = 0; c < m; c++) { for (d = 0 ; d < n; d++) { sum[c][d] = first[c][d] + second[c][d]; printf("%d \ t ", sum[c][d]); } printf(" \ n "); } return 0; } 14.Write a C program to m at rix multiplication using arrays #include <stdio.h> int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[1 0][10], multiply[10][10]; printf("Enter number of rows and columns of first matrix \ n"); scanf("%d%d", &m, &n); printf("Enter elements of first matrix \ n"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &first[c][d]); printf("Enter number of rows and columns of second matrix \ n"); scanf("%d%d", &p, &q); if (n != p) printf("The matrices can't be multiplied with each other. \ n"); else { printf("Enter elements of second matrix \ n"); for (c = 0; c < p; c++) for (d = 0; d < q; d++) scanf("%d", &second[c][d]); for (c = 0; c < m; c++) { for (d = 0; d < q; d++) { for (k = 0; k < p; k++) { sum = sum + first[c][k]*second[k][d]; } multiply[c][d] = su m; sum = 0; } } printf("Product of the matrices: \ n"); for (c = 0; c < m; c++) { for (d = 0; d < q; d++) printf("%d \ t", multiply[c][d]); printf(" \ n"); } } return 0; }