C Program Page 7

C Program Page 7

C Program Page 7
To view other topics related to Computer. Click Here.

Sum of Diagonal matrix

main()

{

int r,c sum=0 ,mat[3][3];

printf(“Enter first matrix\n”);

for(r=0; r<2; r++)

for(c=0; c<2; c++)

scanf(“%d”,&mat[r][c]);

for(r=0; r<2; r++)

{

printf(“%d/t”,mat[r][c]);

sum=sum+mat[r][c];

}

printf(“\n”);

printf(“Sum of matrix =%d\n”,sum);

getch();

}

Multiplication of two matrix

main()

{

intr,c,k,n[3][3],m[3][3],res[3][3];

printf (Enter first matrix \n”);

for(r=0; r<3;r++);

for(c=0; c<3 ;c++);

scanf(“%d”,&n[r][c]);

printf(“Enter second matrix\n”);

for(r 0;r<3 ;r++);

for(c 0;c<3 ; c++);

scanf(“%d”,&m[r][c]);

for(r 0;r <3;r++);

for( c0; c<3; c++);

{

res[r][c]=0;

for(k=0 ;k<3 ;k++);

res[r][c]=res[r][c]+n[r][k]*m[k][c]);

}

printf(“Multiplication of matrix\n”);

for(r=0; r<3;r++)

{

for(c=0; c<3 ;c++)

printf(“%d/t”,res[r][c]);

printf(“\n”);

}

}

Addition of two matrix

main()

{

int n[5][5], m[5][5],l ,j ,res[5][5];

printf(Enter first matrix\n”);

for(i=0<5;l++)

for(i=0; j<5; j++)

scanf(“%d”,&n[l][j]);

printf(“Enter second matrix\n”);

for(i=0 ;l< 5;l++)

for( j=0; j<5 ;j++)

res[l][j] =n[l][j] +m[l][j];

printf(“Resultant matrix\n”);

for(i=0 ;l<5 ;l++)

{

for(i=0; l<5 ;j++)

printf(“%d/t “,res [l][j]);

printf(“\n”);

getch();

}

}

Sum of matrix

main()

{

int r,c sum =0, mat[3][3];

printf((“Enter first matrix\n”);for(r=0; r<2; r++);

for(c=0; c<2; c++)

{

printf(“%d/f”,mat[r][c]);

sum= sum+mat[r][c];

}

printf(“\n”);

printf(Sum of matrix =%d\n”,sum);

getch();

}

}

Display the Largest number and position

main()

{

int l[10], lg, ps =1;

for(i=0 ;i<=9;i++)

{

printf(“Enter number\n”);

scanf(“%d”,&l[i] );

}

lg=l[1];

for(i=2; i<=9 ;i++);

}

if(lg{

if (lg=l[i];

ps= I;

}

printf(“largest No =%d/t\n”, lg);

printf(“position of numbers =%d\n”,ps);

getch();

}

Display the smallest Number And Position

main()

{

int t[10],sam,I,p=0;

for(i=0;i<=9;i++);

{

printf(“Enter numbers\n”);

scanf(“%d”,&t[i]);

}

sam =t[10];

for(i=0;i<=9;i++);

{

if(sam>t[i] )

{

sam=t[i];

p=++I;

}

printf(“smallest = %d/t %d”,sam,p);

getch();

}

Sum of ten numbers

main()

{

int a[10],sum =0,I;

float avg;

for (i=0<=9;i++);

{

printf(“Enter numbers\n”);

scanf(“%d”,&a[i]);

}

for (i=0,i<=9;i++);

sum +=a[i];

avg =aum/10;

printf(“Sum =%d”,sum);

printf(“average =%f”,avg);

getch();

}

Display The List Of Numbers

main()

{

inta[10],I;

for(i=0;i<=9,i++)

{

printf(“Enter the number\n”);

scanf(“%d”,&a[i]);

}

printf(“The list of number \n”);

for(i=0<=9,i++)

{

printf(“%d\n”,a[i]);

}

}

Write a program to perform simple arithmetic operation by using switch statement.

main()

{

int a,b;

char opt;

clrscr();

printf(“Enter any two integer value\n”);

scanf(“%d %d “,&a, &b);

printf(“Enter your option for operation +,-, *, /n”);

scanf(“%c”,opt);

switch(opt)

{

case ‘+’;

printf(“\n\t %d+%d+%d”,a,b,a+b);

break;

case’-‘;

printf(“\n \t %d =%d”, a,b, a-b;

break;

case’*’;

prinff(“\n \t %d+%d=%d”, a,b, a*b);

break;

case’/’;

printf(“\n \t %d %d =%d”,a,b,a/b);

break;

printf(“\n \n press any key to list”);

getch();

}

}

Write a program that will find the sum of those integers. Which are divisible by 2 and are not complete square. The integers should be less then 100

main()

{

int sum=0,I,t;

for(i=2;i<=100; i=i+2)

}

t=sqrt(i);

if(t*t t=i)

sum=sum+I;

}

printf(“%d”,sum);

}

Post a Comment

Previous Post Next Post