0% found this document useful (0 votes)
32 views9 pages

Sum and Average of Three Numbers in C

The document contains C code for several programs: 1) A program to find the sum and average of 3 real numbers. 2) A program to find the largest of 3 numbers using if statements. 3) A program to determine if a number is even or odd using if/else statements. 4) A program to determine if a number is prime or not using a loop. 5) A program to find the addition of two matrices. 6) A program to find the multiplication of two matrices. 7) A program to find the sum of digits of a number.

Uploaded by

vivek2mb
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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

Sum and Average of Three Numbers in C

The document contains C code for several programs: 1) A program to find the sum and average of 3 real numbers. 2) A program to find the largest of 3 numbers using if statements. 3) A program to determine if a number is even or odd using if/else statements. 4) A program to determine if a number is prime or not using a loop. 5) A program to find the addition of two matrices. 6) A program to find the multiplication of two matrices. 7) A program to find the sum of digits of a number.

Uploaded by

vivek2mb
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 DOCX, PDF, TXT or read online on Scribd

PROGRAM TO FIND SUM AND AVERAGE OF 3 REAL NUMBERS

# include<stdio.h> main() { float a,b,c,sum,average; clrscr(); printf(Enter 3 Real Numbers :\n); scanf(%f%f%f,&a,&b,&c); sum=a+b+c; average=sum/3; printf( Sum = %f Average = %f,sum,average); getch(); return 0; }

TO FIND LARGEST OF 3 NUMBERS USING IF STATEMENTS

# include<stdio.h> main() { int a,b,c; clrscr(); printf( Enter the 3 Numbers :\n); scanf(%d%d%d,&a,&b,&c);

if(a>b) { if(a>c) { printf( A is the Largest Number ); } else printf( C is the Largest Number ); } else { if(b>c) { printf( A is the Largest Number ); } else printf( C is the Largest Number ); } getch(); return 0; }

PROGRAM TO FIND EVEN OR ODD USING IF-ELSE


# include<stdio.h> main() { int num; clrscr(); printf( Enter the Numbers:\n); scanf(%d, &num); if(num%2==0) printf( The Number is Even); else printf( The Number is Odd); getch(); return 0; }

PROGRAM TO FIND THE NUMBER IS PRIME OR NOT ( USING LOOP)


# include<stdio.h> main() { int num, i =1; clrscr(); printf( Enter the Numbers:\n); scanf(%d, &num); while(i<=num) { i++; if(num%i==0) break; } if(i==num) { printf( The Number is Prime Number ); else printf( The Number is Not a Prime Number); } getch(); return 0; }

PROGRAM TO FIND THE ADDITION OF TWO MATRIX #include<stdio.h> main() { int i,j,k,r,c; int a[10][10], b[10][10], sum[10][10]; clrscr(); printf(Enter the Size of Row & Column of Matrix:\n); scanf( %d %d,&i,&j); printf(Enter the Elements of Matrix 1\n); for(i=0; i<r; i++) { for(j=0; j<c; j++) { scanf(%d,&a[i][j]); } } printf(Enter the Elements of Matrix 2\n); for(i=0; i<r; i++) { for(j=0; j<c; j++) { scanf(%d,&b[i][j]); } } for(i=0; i<r; i++) { for(j=0; j<c; j++) { sum[i][j]=a[i][j]+b[i][j]; } }

printf(Addition of Matrix\n); for(i=0; i<r; i++) { for(j=0; j<c; j++) printf(%d\t,sum[i][j]); printf(\n); } getch(); return 0; }

PROGRAM TO FIND THE MULTIPLICATION OF TWO MATRIX

#include<stdio.h> main() { int i,j,k,r,c; int a[10][10], b[10][10], M[10][10], r, c,k; clrscr(); printf(Enter the Size of Row & Column of Matrix:\n); scanf( %d %d,&r,&c); printf(Enter the Elements of Matrix 1\n); for(i=0; i<r; i++) { for(j=0; j<c; j++) { scanf(%d,&a[i][j]); } } printf(Enter the Elements of Matrix2\n); for(i=0; i<r; i++) { for(j=0; j<c; j++) { scanf(%d,&b[i][j]); } } for(i=0; i<r; i++) { for(j=0; j<c; j++) { M[i][j]=0; for(k=0; k<=R; k++)

M[i][j]=M[i][j]+(a[i][j]*b[j][i]); } } printf(Multiplication of Matrix\n); for(r=0; r<=R; r++) { for(c=0; c<=C; c++) printf( %d\t,M[r][c]); printf(\n); } getch(); return 0; }

#include<stdio.h> #include<conio.h> void main() { int n,s=0,r; clrscr(); printf("Enter the number"); scanf("%d",&n); do { r=n%10; s=s+r; n=n/10; }while(n!=0); printf("the sum is %d",s); getch(); }

You might also like