Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C program we will add two matrices(3*3) and print the result on the screen.The elements of the matrices will be taken from the user.
input:
The elements of matrices(3*3).output:
The Sum of the two matrices.
CODE---->
#include<stdio.h>
int main()
{
int mat1[10][10],mat2[10][10],mat3[20][20],i,j;
printf("Please,Enter the first matrix--->> ");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\nPlease,Enter data: ");
scanf("%d",&mat1[i][j]);
}
}
printf("\n\nPlease,Enter the second matrix--->> ");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\nPlease,Enter data: ");
scanf("%d",&mat2[i][j]);
}
}
printf("\n\nThe sum of the matrices --->> \n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
mat3[i][j]=mat1[i][j]+mat2[i][j];
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf(" %d ",mat1[i][j]);
}
printf("\n");
}
printf(" +\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf(" %d ",mat2[i][j]);
}
printf("\n");
}
printf(" ||\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf(" %d ",mat3[i][j]);
}
printf("\n");
}
return 0;
}
Download the C-Program file of this Program.
RESULT :
Please,Enter the first matrix--->> Please,Enter data: 11 Please,Enter data: 22 Please,Enter data: 33 Please,Enter data: 44 Please,Enter data: 55 Please,Enter data: 66 Please,Enter data: 77 Please,Enter data: 88 Please,Enter data: 99 Please,Enter the second matrix--->> Please,Enter data: 9 Please,Enter data: 8 Please,Enter data: 7 Please,Enter data: 6 Please,Enter data: 5 Please,Enter data: 4 Please,Enter data: 3 Please,Enter data: 2 Please,Enter data: 1 The sum of the matrices --->> 11 22 33 44 55 66 77 88 99 + 9 8 7 6 5 4 3 2 1 || 20 30 40 50 60 70 80 90 100 -------------------------------- Process exited after 24.41 seconds with return value 0 Press any key to continue . . .
Images for better understanding :
Comments
Post a Comment