0
Write a complete C program to calculate and print the summation of the elements of a primary diagonal of an integer square 5x5 a
4 Réponses
+ 4
just 2 minor edits..
1. you forgot #
preprossed ststements start with a # symbol in C
2. you didn't considered non square matrix .
here's the modified code .
https://code.sololearn.com/creX6I3JkQUe/?ref=app
and one more thing . please post your code on code playground (may be keep it private if you want to) and provide us with a link . that saves our time a little.
+ 3
include<stdio.h>
int main()
{
int i, j, rows, columns, a[10][10], Sum = 0;
printf("\n Please Enter Number of rows and columns : ");
scanf("%d %d", &i, &j);
printf("\n Please Enter the Matrix Elements \n");
for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &a[rows][columns]);
}
}
for(rows = 0; rows < i; rows++)
{
Sum = Sum + a[rows][rows];
}
printf("\n The Sum of Diagonal Elements of a Matrix = %d", Sum );
return 0;
}
+ 2
Hi! Please, show us your code attempt! Thx!
+ 1
HASHEM AL_NASRE your question description state about a square 5x5 a(rray) but in your code you declare a 10x10 array and ask user for two dimensions (wich could be everything: not equals -- not square -- as well as greater than 10)...
anyway, Prashanth Kumar [back again] is right for its first point: 'include' preprocessor statement should start with '#' (maybe you have it in your original code and you doesn't select it when copy-pasting: that's one reason why it is better to share a link to your code rather than copy pasting it ^^)