You are on page 1of 8

CS LAB 5

Diksha Chauhan (2K20/B12/50)

Q1(a).
#include<stdio.h>

int main()
{
int row,col,c;
int i,j;
printf("Enter the no. of Rows of the matrix:");
scanf("%d",&row);
printf("Enter the no. of Columns of the matrix:");
scanf("%d",&col);
int A[row][col];
printf("Enter the elements of the matrix : ");
for( i=0;i<row;i++)
{
for( j=0;j<col;j++)
{
scanf("%d",&A[i][j]);
}
}

printf("Enter the constant : ");


scanf("%d",&c);

for( i=0;i<row;i++)
{
for( j=0;j<col;j++)
{
A[i][j]=c*A[i][j];
printf("|| %d ||",A[i][j]);

}
printf("\n");
}

return 0;
}

Q1(b).
#include<stdio.h>
int main()
{
int A[3][3],B[3][3],i,j;
printf("Enter the matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&A[i][j]);
printf("\n");
}

printf("\nThe transposed matrix is\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d\t",A[j][i]);
printf("\n");
}
return 0;

}
Q1.(c)
#include<stdio.h>
int main()
{
int A[3][3],B[3][3],C[3][3],i,j,k;
printf("Enter the first matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&A[i][j]);
printf("\n");
}

printf("Enter the second matrix\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&B[i][j]);
printf("\n");
}

//multiplying matrix
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
C[i][j]=0;
for(k=0;k<3;k++)
C[i][j]+=A[i][k]*B[k][j];
}

printf("\nThe product matrix is\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d\t",C[i][j]);
printf("\n");
}
return 0;
}

Q3.
#include<stdio.h>
int main()
{
int A[10],i,max=0;
printf("Enter the number array(Total 10)\n");
for(i=0;i<10;i++)
scanf("%d",&A[i]);

//finding maximum
for(i=0;i<10;i++)
if(A[i]>max)
max=A[i];
printf("\nThe array is\n");

for(i=0;i<10;i++)
printf("%d\t",A[i]);

printf("\nThe maximum value is %d\n",max);


}
Q4.
#include<stdio.h>
int main()
{
int A[3][3],i,j,max=0,min;
printf("Enter the matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&A[i][j]);
printf("\n");
}
//maximum
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(A[i][j]>max)
max=A[i][j];

//minimum
min=A[0][0];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(A[i][j]<min)
min=A[i][j];

printf("\nThe matrix is\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d\t",A[i][j]);
printf("\n");
}

printf("\nThe maximum is %d\n",max);


printf("\nThe minimum is %d\n",min);

return 0;
}

You might also like