Professional Documents
Culture Documents
#include <stdio.h> void main() { float a, b, c, sum, avg; printf("\nEnter value of three numbers: "); scanf("%f %f %f", &a, &b, &c); sum = a + b + c; avg = sum / 3; printf("\nSum = %.2f", sum); printf("\nAverage = %.2f", avg); getch(); }
printf("\nSphere Surface Area = %.2f", area); printf("\nVolume of Sphere = %.2f", vol); getch(); }
case 'U': printf("\n\n%c is a vowel", ch); break; default: printf("\n\n%c is not a vowel", ch); } getch(); }
Program to Find the Sum of Even and Odd Numbers from First 100 Positive Integers
#include <stdio.h> void main() { int i, sumEven=0, sumOdd=0; for (i=0; i<=100; i++) if (i%2 == 0) sumEven = sumEven + i; else sumOdd = sumOdd + i; printf("\nSum of first even 100 numbers: %d\n", sumEven); printf("\nSum of first odd 100 numbers: %d\n", sumOdd); getch(); }
printf("\nEnter any number: "); scanf("%d", &n); while (n > 0) { digit = n%10; n = n/10; sum = sum + digit; } printf("\n\nSum of digits: %d", sum); getch(); }
Program to Print the Numbers, Which are Divisible by 3 and 5 from First 100 Natural Numbers
#include <stdio.h> void main() { int i; printf("\nFirst 100 numbers which are divisible by 3 and 5\n\n"); for (i=1; i<=100; i++) if (i%3==0 && i%5==0) printf("\t%d", i); getch(); }
} if (n > m) { temp = m; m = n; n = temp; } q = 1; while (q != 0) { q = m % n; if (q != 0) { m = n; n = q; } } printf("\nHCF of number is: %d", n); end: getch(); }
Program to multiply two matrices. The order and the elements of the two matrices
will be entered by the user as input to the program and if multiplication is not possible then it should be reported to the user #include <stdio.h> void main() { int a[10][10], b[10][10], c[10][10], i, j, k, r1, r2, c1, c2; printf("\nEnter no. of rows and columns of Matrix A: "); scanf("%d %d", &r1, &c1); printf("\nEnter no. of rows and columns of Matrix B: "); scanf("%d %d", &r2, &c2); if (c1 != r2) { printf("\n\nMultiplication is not possible\n"); goto back; } printf("\n\nEnter elements of Matrix A:\n"); for (i=0; i<r1; i++) for (j=0; j<c1; j++) scanf("%d", &a[i][j]); printf("\nEnter elements of Matrix B:\n"); for (i=0; i<r2; i++) for (j=0; j<c2; j++) scanf("%d", &b[i][j]); printf("\n\nElements 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\nElements 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\nMultiplication of Matrices:\n\n"); for (i=0; i<r1; i++) { for (j=0; j<c2; j++) printf("\t%d", c[i][j]); printf("\n\n"); } getch(); }
int big(int a[], int n) { int b, i; b = a[0]; for (i=0; i<n; i++) if (a[i] > b) b = a[i]; return b; }
{ char s1[20]; int len; printf("\nEnter any string: "); gets(s1); len = strlen(s1); printf("\nLength of string: %d", len); getch(); }
getch(); }