I have been trying to solve and sum the each row in the problem for like trying to from last two days with no luck . kinda new to programming and please help me out with this….the real problem im facing is when im trying to sum after initializing the the array of 20 students with 5 subjects ,in the first case i got sum of garbage value many times now im ended up with garbage of a code below.
im trying to oragnize the code function wise too!
would be gratefull if someone helps!
the problem says to find sum of each students marks average , number of students who have scored
below 50 in their average, he scores obtained by every student.
i dont wanna use pointers since it kinda messes up readability.
#include <stdio.h>
int sumofmarks();
int main(){
int row,col;
printf("Enter the total number of student = "); `students as columns`
scanf("%d",&col);
printf("Total number of subjects = ");
scanf("%d",&row); `put marks as rows`
int marks[col][row];
for (int i=0; i<row; i++) {
for(int j = 0; j<col; j++){
printf("Enter the marks obtained by %d student n in %d subject = ",i+1,j+1);
scanf("%d",&marks[i][j]);
}
}
sumofmarks(marks,row,col); `fuction call`
}
int sumofmarks(int marks[10][10],int r,int c){ `sum funtion defination`
int sum = 0;
for (int i=0; i < r; i++) {
sum=0;
for(int j = 0; j < c; j++){
sum +=marks[i][j];
}
printf("nThe Sum of marks of student %d is %d in 5 subjects",i+1,sum );
}
return sum;
}
Aamir Abbas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.