Input number of rows: 2
Input number of columns: 2
Input value of row 0 and column 0:
Input value of row 0 and column 1:
Input value of row 1 and column 0:
Input value of row 1 and column 1:
SUMMARY:
The sum of column 1 is...
The sum of column 2 is...
The difference of column 1 is ...
The product of column is 1 ....
The smallest element in column 1 is .....
#include <stdio.h>
#define N 100
#define M 100
int main() {
int n, m;
int arr[N][M];
int i, j;
int sum, dif, prod, small;
printf("Input number of rows: ");
scanf("%d", &n);
printf("Input number of columns: ");
scanf("%d", &m);
for (i=0; i<n; i++) {
for (j=0; j<m; j++) {
printf("Input value of row %d and column %d: ", i, j);
scanf("%d", &arr[i][j]);
}
}
printf("SUMMARY:\n");
for (j=0; j<m; j++) {
sum = 0;
for (i=0; i<n; i++) {
sum += arr[i][j];
}
printf("The sum of column %d is %d\n", j+1, sum);
}
dif = arr[0][0];
for (i=1; i<n; i++) {
dif -= arr[0][i];
}
printf("The difference of column 1 is %d\n", dif);
prod = arr[0][0];
for (i=1; i<n; i++) {
prod *= arr[0][i];
}
printf("The product of column 1 is %d\n", prod);
small = arr[0][0];
for (i=1; i<n; i++) {
if (arr[0][i]<small) {
small = arr[0][i];
}
}
printf("The smallest element in column 1 is %d\n", small);
return 0;
}
Comments
Leave a comment