home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
grades.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
816b
|
35 lines
/*GRADES.C--Example program with array */
/* Get 10 grades and then average them */
#include <stdio.h>
#define MAX_GRADE 100
#define STUDENTS 10
int grades[STUDENTS];
int idx;
int total = 0; /* used for average */
main()
{
for( idx = 0; idx < STUDENTS; idx++ )
{
printf( "Enter Person %d's grade: ", idx +1);
scanf( "%d", &grades[idx] );
while ( grades[idx] > MAX_GRADE )
{
printf( "\nThe highest grade possible is %d", MAX_GRADE );
printf( "\nEnter correct grade: " );
scanf( "%d", &grades[idx] );
}
total += grades[idx];
}
printf( "\n\nThe average score is %d", ( total / STUDENTS ) );
return (0);
}