FOLLOW DIRECTIONS USING \"C\" ONLY MUST USE \"FOR\" LOOP AND MULTIDIMENSIONAL AR
ID: 2248970 • Letter: F
Question
FOLLOW DIRECTIONS USING "C" ONLY MUST USE "FOR" LOOP AND MULTIDIMENSIONAL ARRAY ILL RATE POORLY IF DIRECTIONS NOT FOLLOWED nsion of a n x n matrix (ask the value for "n"), take rix, then compute the sum of all upper diagonal 3. Create a script that will prompt the user the o all the user input for the individual entry of the elements and the sum of all lower diagonal eiements You need to use Multidimensional Array and For to use loops. 3 4] Upper Diagonal Line 13 14 15 16 Lower Diagonal Line For this matrix, since n is 4, the user should be prompted 17 times (Once for n value, and 16 times for the entries of the matrix-nxn times). The sum of Upper Diagonal Line should be 2+7+12 -21 and the sum of Lower Diagonal Line should be 5+10+15-30Explanation / Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j, U_diag_sum, L_diag_sum, A[10][10];
U_diag_sum=0;
L_diag_sum=0;
printf(" Enter size of the matrix : ");
scanf("%d",&n);
/* Storing elements in the matrix */
printf(" Enter elements of the matrix: ");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
printf(" Enter element a%d%d: ",i,j);
scanf("%d", &A[i][j]);
}
/* Calculating upper diagonal sum */
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(j-i==1)
U_diag_sum=U_diag_sum+A[i][j];
}
printf(" Upper diagonal sum = %d", U_diag_sum);
/* Calculating lower diagonal sum */
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(i-j==1)
L_diag_sum=L_diag_sum+A[i][j];
}
printf(" Lower diagonal sum=%d",L_diag_sum);
getch();
}
Please share your valuable feedback.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.