Hello, i have some problems with my c code, could you help me?
it's returns randomly numbers for averages.
#include<stdio.h>
#include<stdlib.h>
struct Student MStudent(struct Student std);
void CalcAvrg(struct Student std);
struct Student{
int mark[5][5];
};
struct Student MStudent(struct Student std){
int i,j;
for(i=0;i<5;i++){
for(j=0;j<5;j++){
printf("%d. Student's mark for %d. exam :\n", i+1,j+1);
scanf("%d", &std.mark[i][j]);
}
}
return std;
}
void CalcAvrg(struct Student std){
int i;
for(i=0;i<5;i++){
printf("%d. Exam's average is: %d\n", i+1,
(std.mark[0][i] +std.mark[1][i] + std.mark[2][i]+ std.mark[3][i]+ std.mark[4][i])/5);
}
}
int main(){
struct Student dene;
MStudent(dene);
CalcAvrg(dene);
return 0;
}
i wrote it in this way too, but it didnt compile in Dev c++;
#include<stdio.h>
#include<stdlib.h>
struct Student
{
int mark[5][5] = {{0}};
};
void MStudent( Student& myStruct);
void CalcAvrg( Student& myStruct);
int main()
{
struct Student dene;
MStudent(dene);
CalcAvrg(dene);
return 0;
}
void MStudent( Student& myStruct)
{
int i,j;
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
{
printf("%d. Student's mark for %d. exam :\n", i+1,j+1);
scanf("%d", &myStruct.mark[i][j]);
}
}
}
void CalcAvrg( Student& myStruct)
{
int i;
for(i=0; i<5; i++)
{
printf("%d. Exam's average is: %d\n", i+1,
(myStruct.mark[0][i] + myStruct.mark[1][i] +
myStruct.mark[2][i] + myStruct.mark[3][i] +
myStruct.mark[4][i])/5);
}
}