Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the difference between far and near ?

1156


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

1096


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

1090


Are pointers integers in c?

1029


What is a far pointer in c?

990


How can I do serial ("comm") port I/O?

1131


What is header file in c?

1024


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

1419


Why c language is called c?

950


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

1089


What is the difference between union and structure in c?

1084


what is the diffrenet bettwen HTTP and internet protocol

1786


What is data structure in c language?

1056


What does 3 mean in texting?

1030


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

1186