write a program to print sum of each row of a 2D array.
Answer Posted / mark
/*
* C Program to find sum of each row and column of matrix
*/
#include <stdio.h>
#include <conio.h>
int main(){
int rows, cols, rowCounter, colCounter;
int inputMatrix[50][50], rowSum[50] = {0};
printf("Enter size of a matrix
");
scanf("%d %d", &rows, &cols);
printf("Enter matrix of size %dX%d
", rows, cols);
/* Input matrix */
for(rowCounter = 0; rowCounter < rows; rowCounter++){
for(colCounter = 0; colCounter < cols; colCounter++){
scanf("%d", &inputMatrix[rowCounter][colCounter]);
}
}
/* Calculate sum of each row and column */
for(rowCounter = 0; rowCounter < rows; rowCounter++){
for(colCounter = 0; colCounter < cols; colCounter++){
/* Add this element in it's row sum */
rowSum[rowCounter] += inputMatrix[rowCounter][colCounter];
}
}
/* Print rows sum */
for(rowCounter = 0; rowCounter < rows; rowCounter++){
printf("Sum of row number %d is %d
",
rowCounter, rowSum[rowCounter]);
}
getch();
return 0;
}
Source : http://www.techcrashcourse.com/2015/03/c-program-sum-each-row-and-column.html
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is the difference between far and near ?
any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
Are pointers integers in c?
What is a far pointer in c?
How can I do serial ("comm") port I/O?
What is header file in c?
In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping
Why c language is called c?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
What is the difference between union and structure in c?
what is the diffrenet bettwen HTTP and internet protocol
What is data structure in c language?
What does 3 mean in texting?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?