write a program to print sum of each row of a 2D array.

Answers were Sorted based on User's Feedback



write a program to print sum of each row of a 2D array. ..

Answer / 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

write a program to print sum of each row of a 2D array. ..

Answer / khurshid alam

#include<stdio.h>
int main()
{
int a[3][3]={{2,5},{7,8},{1,1}};
int b[3][3]={{5,6},{9,3},{1,1}},i,j,*m,*n,s=0;
n=&a[j][i];
m=&b[j][i];
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
s+=a[i][j]+b[i][j];

}

}
printf("Sum :%d",s);
return 0;

}

Is This Answer Correct ?    5 Yes 2 No

write a program to print sum of each row of a 2D array. ..

Answer / 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

write a program to print sum of each row of a 2D array. ..

Answer / vignesh1988i

first ordinary logic.
LOGIC 1
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50],k,row,column;
printf("enter the number of rows and columns of 2D array :");
scanf("%d%d",&row,&column);
for(int i=0;i<row;i++)
{
for(int q=0;q<column;q++)
{
scanf("%d",&a[i][q]);
}
}
for(i=0;i<row;i++)
{
k=0;
for(q=0;q<column;q++)
{
k=k+a[i][q];
}
printf("%d\n",k);
}
getch();
}

Is This Answer Correct ?    20 Yes 32 No

Post New Answer

More C Interview Questions

what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); }

6 Answers   Microsoft,


What is union and structure in c?

0 Answers  


Explain what header files do I need in order to define the standard library functions I use?

0 Answers  


how can we use static and extern?and where can we use this?

3 Answers   Excel,


i need all types of question paper releted to "c" and other language.

0 Answers  






write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]

7 Answers  


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

0 Answers  


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

0 Answers  


Difference between linking and loading?

0 Answers  


What is restrict keyword in c?

0 Answers  


2) Write a program that will help Air Traffic Control for an airport to view the sequence of flights ready for take-off. The airport can accommodate 10 flights waiting for take-off at any point in time. Each flight has a unique 3 digit numeric identifier. &#61550; Each time a flight takes-off, Air Traffic Control adds a flight to the waitlist. Each time a flight is added to the waitlist, the list of flights waiting to take-off must be displayed. &#61550; When a flight is cleared for take-off, Air Traffic Control removes the flight from the waitlist. Each time a flight takes-off, the list of flights waiting to take-off must be displayed. &#61550; Sequence of take-off is the sequence of addition to the waitlist

0 Answers  


Is void a keyword in c?

0 Answers  


Categories