Home > Back-end >  C language structure types, the output student information.
C language structure types, the output student information.

Time:12-17

Why do the input data.
Did anyone give me have a look, what's the problem
Code is a little more, but is very simple, immediately understand the sort of,
For bosses to help see,
The code is as follows:
# include
Struct ST
{
Char id [5];
char name[10];
Float score [3].
};
Struct ST stu [3].
Int Max (a, float float b, float c)
{
Float t, Max;
A. & gt; B? T=a: t=b;
Return (c & gt; T? Max=c: Max=t);
}
Int main ()
{
int i,j;
Float sum=0, s1=0, s2=0, s3=0, ave;
For (I=0; I & lt; 3; I++)
{
Printf (" please enter the first % d student information (except grades) : \ n ", I + 1);
The scanf (" % s ", stu [I] id);
The scanf (" % s ", stu [I] name);
For (j=0; J & lt; 3; J++)
{
Printf (" please enter the first % d students of three grades: \ n ", j + 1);
The scanf (" % f ", & amp; Stu [I] score [j]);
The sum +=stu [I] score [j];
If (j=0)
S1 +=stu [I] score [j];
If (j=1)
S2 +=stu [I] score [j];
The else
S3 +=stu [I] score [j];
}
}
Ave=sum/3;
Printf (" gpa is: % 2 f \ n ", ave);
Printf (" top student information is: \ n ");
If (Max (s1, s2, s3)==s1)
{
Student id: printf (" % s \ n ", stu. [0] id);
Printf (" name: % s \ n ", stu. [0] name);
Printf (" grade: % 2 f, %, 2 f, %, 2 f \ n ", stu. [0] score [0], stu. [0] score [1], stu [0]. Score [2]).
}
If (Max (s1, s2, s3)==s2)
{
Student id: printf (" % s \ n ", stu. [1] id);
Printf (" name: % s \ n ", stu. [1] name);
Printf (" grade: % 2 f, %, 2 f, %, 2 f \ n ", stu. [1] score [0], stu. [1] score [1], stu. [1] score [2]).
}
The else
{
Student id: printf (" % s \ n ", stu. [2] id);
Printf (" name: % s \ n ", stu. [2] name);
Printf (" grade: % 2 f, %, 2 f, %, 2 f \ n ", stu. [2] score [0], stu. [2] score [1], stu. [2] score [2]).
}
return 0;
}

CodePudding user response:

If (j=0) to if (j==0); The if statement below to change to same==

CodePudding user response:

Modified as follows, for your reference:
 # include 

Struct ST {
Char id [5];
char name[10];
Float score [3].
};

Struct ST stu [3].

Int Max (a, float float b, float c)
{
//float t, Max;
//a & gt; B? T=a: t=b;
//return (c & gt; T? Max=c: Max=t);
Return ((a) & gt; (b)? (a) & gt; (c)? (a) : (c)) : ((b) & gt; (c)? (b) (c)));
}



Int main (int arg c, char * argv [])
{
int i,j;
Float sum [3], ave=0, Max, s1=0, s2=0, s3=0;
For (I=0; I & lt; 3; I++)
{
The sum [I]=0;
Printf (" please enter the first % d a student's name and student id: \ n ", I + 1);
The scanf (" % s ", stu [I] id);
The scanf (" % s ", stu [I] name);
Printf (" please enter the first % d students of three grades: \ n ", I + 1);
For (j=0; J & lt; 3; J++)
{
The scanf (" % f ", & amp; Stu [I] score [j]);
The sum [I] +=stu [I] score [j];
}
}

Max=sum [0];
for(i=0; i<3; I++) {
Ave +=sum [I]/3;
If (max}
Printf (" total grade point average is: % 2 f \ n ", ave/3);
for(i=0; i<3; I++) {
If (Max==sum [I])
Printf (" top student information is: \ n student id: % s \ n name: % s \ n grade: %, 2 f, %, 2 f, %, 2 f \ n ",
Stu [I]. Id, stu [I]. Name, stu [I] score [0], stu [I] score [1], stu [I] score [2]);
}
/*
If (j=0)
S1 +=stu [I] score [j];
If (j=1)
S2 +=stu [I] score [j];
The else
S3 +=stu [I] score [j];

Ave=sum/3;
Printf (" gpa is: % 2 f \ n ", ave);
Printf (" top student information is: \ n ");
If (Max (s1, s2, s3)==s1)
{
Student id: printf (" % s \ n ", stu. [0] id);
Printf (" name: % s \ n ", stu. [0] name);
Printf (" grade: % 2 f, %, 2 f, %, 2 f \ n ", stu. [0] score [0], stu. [0] score [1], stu [0]. Score [2]).
}
If (Max (s1, s2, s3)==s2)
{
Student id: printf (" % s \ n ", stu. [1] id);
Printf (" name: % s \ n ", stu. [1] name);
Printf (" grade: % 2 f, %, 2 f, %, 2 f \ n ", stu. [1] score [0], stu. [1] score [1], stu. [1] score [2]).
}
The else
{
Student id: printf (" % s \ n ", stu. [2] id);
Printf (" name: % s \ n ", stu. [2] name);
Printf (" grade: % 2 f, %, 2 f, %, 2 f \ n ", stu. [2] score [0], stu. [2] score [1], stu. [2] score [2]).
} */
system("pause");
return 0;
}

CodePudding user response:

Missed an average scores, complement changes:
 # include 

Struct ST {
Char id [5];
char name[10];
Float score [3].
};

Struct ST stu [3].

Int Max (a, float float b, float c)
{
//float t, Max;
//a & gt; B? T=a: t=b;
//return (c & gt; T? Max=c: Max=t);
Return ((a) & gt; (b)? (a) & gt; (c)? (a) : (c)) : ((b) & gt; (c)? (b) (c)));
}



Int main (int arg c, char * argv [])
{
int i,j;
Float sum [3], ave=0, Max, s1=0, s2=0, s3=0;
For (I=0; I & lt; 3; I++)
{
The sum [I]=0;
Printf (" please enter the first % d a student's name and student id: \ n ", I + 1);
The scanf (" % s ", stu [I] id);
The scanf (" % s ", stu [I] name);
Printf (" please enter the first % d students of three grades: \ n ", I + 1);
For (j=0; J & lt; 3; J++)
{
The scanf (" % f ", & amp; Stu [I] score [j]);
The sum [I] +=stu [I] score [j];
}
}

Max=sum [0];
for(i=0; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related