Solution:
#include <stdio.h>
void main()
{
int a[10][10], transpose[10][10], r, c, i, j,sum=0, fig_code;
printf("Enter rows and columns of matrix: ");
scanf("%d %d", &r, &c);
// Storing elements of the matrix
printf("\nEnter elements of matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1, j+1);
scanf("%d", &a[i][j]);
}
printf("-------------------------\n");
printf(" 1 --> Transpose\n");
printf(" 2 --> Sum of odd elements\n");
printf("-------------------------\n");
printf("Enter the Figure code\n");
scanf("%d", &fig_code);
switch(fig_code)
{
case 1:
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
transpose[j][i] = a[i][j];
}
printf("\nTranspose of Matrix:\n");
for(i=0; i<c; ++i)
for(j=0; j<r; ++j)
{
printf("%d ",transpose[i][j]);
if(j==r-1)
printf("\n\n");
}
break;
case 2:
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
if(a[i][j]%2!=0)
sum=sum+a[i][j];
}
printf("\n sum of odd elements= %d",sum);
break;
default:
printf("Error in figure code\n");
break;
}
}
0 Comments