Programming C, not C++. erpoint offi app li e com p PowerPointFrame.aspx?PowerPo
ID: 3704423 • Letter: P
Question
Programming C, not C++. erpoint offi app li e com p PowerPointFrame.aspx?PowerPointView SlideShov View&u; en-US&rs; en US&WOPIS; rc=https%3A%2F%2F utlook office com%2F Graded Practice 2D Array: Given the 2D array below, write a program to print the sum of each row, column, and diagonals. The results should look like this: 7 -3 2 7 -3 2 1 6 5 1 9I 15 13 0 14 7 26 min (10%) remaining Your battery is low a0%). If you need te your computer, either plug in your com down and then change the battery.Explanation / Answer
#include<stdio.h>
int main()
{
int n;
printf("enter the size of an array");
scanf("%d",&n);
int a[n][n];
printf("enter the elements into the array ");
int i,j,diagonal1=0,diagonal2=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(i+j==n-1)
diagonal2+=a[i][j];
}
printf(" the Resultant 2d matrix ");
for(i=0;i<n;i++)
printf(" ");
printf("|%2d ",diagonal2);
for(i=0;i<n;i++)
{ int sum=0;
for(j=0;j<n;j++)
{
sum+=a[i][j];
printf("%2d ",a[i][j]);
if(i==j)
diagonal1+=a[i][j];
}
printf("|%2d ",sum);
}
printf(" ");
for(i=0;i<n;i++)
printf("-- ");
printf(" ");
for(i=0;i<n;i++)
{int sum=0;
for(j=0;j<n;j++)
sum+=a[j][i];
printf("%2d ",sum);
}
printf("%2d",diagonal1);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.