problem number 1 (a):
#include<stdio.h>
int main()
{
int a[4][4] = {3,5,1,1,5,8,2,2,9,8,7,1,6,3,2,1}, i, j;
for(i=0; i<4; i++){
for(j=0; j<4; j++){
if(j>i)
a[i][j] = 0;
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
problem 1(b) :
#include<stdio.h>
int main()
{
int a[4][4] = {3,5,1,1,5,8,2,2,9,8,7,1,6,3,2,1}, i, j;
for(i=0; i<4; i++){
for(j=0; j<4; j++){
if(j>i)
a[i][j] = 0;
if(i>j)
a[i][j] = 0;
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
int main()
{
int a[4][4] = {3,5,1,1,5,8,2,2,9,8,7,1,6,3,2,1}, i, j;
for(i=0; i<4; i++){
for(j=0; j<4; j++){
if(j>i)
a[i][j] = 0;
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
problem 1(b) :
#include<stdio.h>
int main()
{
int a[4][4] = {3,5,1,1,5,8,2,2,9,8,7,1,6,3,2,1}, i, j;
for(i=0; i<4; i++){
for(j=0; j<4; j++){
if(j>i)
a[i][j] = 0;
if(i>j)
a[i][j] = 0;
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
..........................................................................................................................................................
Problem number 2 : transpose matrix.
#include<stdio.h>
int main()
{
//print original matrix.
int a[4][4] = {3,5,1,1,5,8,2,2,9,8,7,1,6,3,2,1}, b[3][3], i, j;
printf("The original matrix is ...\n");
for(i=0; i<4; i++){
for(j=0; j<4; j++){
printf("%d ",a[i][j]);
}
printf("\n");
}
//transpose matrix and store it for matrix b[3][3].
printf("Th matrix after transpose is ...\n");
for(i=0;i<4; i++){
for(j=0; j<4; j++){
b[i][j] = a[j][i];//transpose and store for b[i][j].
printf("%d ",b[i][j]);
}
printf("\n");
}
return 0;
}
................................................................................................................
problem number 3 : add two matrix
#include<stdio.h>
int main()
{
int a[3][3] = {1,1,1,1,1,1,1,1,1}, b[3][3] = {1,1,1,1,1,1,1,1,1}, c[3][3], i, j;
for(i=0; i<3; i++){
for(j=0; j<3; j++){
c[i][j] = a[i][j] + b[i][j];
printf("%d ",c[i][j]);
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment