1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char name [][30]={};
int score [5];
int x,y,num;
float sum=0,ave=0;
float large=0,min=1000;
printf("Enter how many elements do you want : n");
scanf("%d",&num);
fflush(stdin);
for(x=0;x<num;x++)
{
fflush(stdin);
printf("Enter name %d : n", x);
gets(name[x]);
sum=0;
for(y=0;y<5;y++)//inner loop
{
printf("Enter score %d : n", y);
scanf("%d", &score[y]);
if(score[y] >0)
sum+=score[y];
else
{
y=0;
sum=0;
}
}
fflush(stdin);
ave=(sum/5);
printf("Average for %s is : %.2f n", name[x], ave );
if(ave > large)
large=ave;
if(ave < min)
min=ave;
}//outer loop
printf("Highest is %s : %.2f n", name[x], large);
printf("Lowest is %s : %.2f n", name[x], min);
getch();
}
|