write a program to print sum of each row of a 2D array.
Answer Posted / poornima
int b[20];
int main()
{
int a[20][20],row,col,i,j;
printf("Row & col : ");
scanf("%d %d",&row,&col);
printf("\nEnter elements : ");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nElements are\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
b[i] +=a[i][j];
}
}
for(i=0;i<row;i++)
{
printf("Sum of row %d is %d\n",(i+1),b[i]);
}
return 0;
}
| Is This Answer Correct ? | 43 Yes | 35 No |
Post New Answer View All Answers
What is a lvalue
Explain how many levels deep can include files be nested?
The program will first compute the tax you owe based on your income. User is prompted to enter income. Program will compute the total amount of tax owed based on the following: Income Tax 0 - $45,000 = 0.15 x income $45,001 - $90,000 = 6750 + 0.20 x (income – 45000) $90,001 - $140,000 = 15750 + 0.26 x (income – 90000) $140,001 - $200,000 = 28750 + 0.29 x (income – 140000) Greater than $200,000 = 46150 + 0.33 x (income – 200000) Dollar amounts should be in dollars and cents (float point numbers with two decimals shown). Tax is displayed on the screen.
How can I copy just a portion of a string?
Why are all header files not declared in every c program?
What is the difference between malloc calloc and realloc in c?
What is the use of function overloading in C?
What is the purpose of main( ) in c language?
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
How can I do serial ("comm") port I/O?
What is an array? What the different types of arrays in c?
Explain main function in c?
Explain how can a program be made to print the line number where an error occurs?
Is c is a procedural language?
What are the __date__ and __time__ preprocessor commands?