+ 2
It gives no output why
2 Réponses
+ 1
This gives some output. I didn't do much more than fix all the compiler warnings and runtime errors I saw:
#include <stdio.h>
int max,total[15],i;
int all_topper();
int hindi_topper();
int english_topper();
int computerscience_topper();
struct student
{
char name[100];
int sub_hindi;
int sub_english;
int sub_computerscience;
};
struct student s[15];
int main() {
for(i=0;i<15;i++)
{
printf("enter name \n");
scanf("%s", s[i].name);
printf("\n entermarks in three subject=");
scanf("%d %d %d",&s[i].sub_hindi,&s[i].sub_english,&s[i].sub_computerscience );
total[i]=s[i].sub_hindi+s[i].sub_english+s[i].sub_computerscience;
}
all_topper ();
hindi_topper ();
english_topper ();
computerscience_topper();
return 0;
}
int all_topper ()
{
int n=0;
max=total[0];
for(i=0;i<15;i++)
{
if(max<total[i])
{
max=total[i];
n=i;
}
}
printf ("over all topper is:\n");
printf("%s\n",s[n].name);
return 0;
}
int hindi_topper ()
{
int n=0;
max=s[0].sub_hindi ;
for(i=0;i<15;i++)
{
if(max<s[i].sub_hindi )
{
max=s[i].sub_hindi ;
n=i;
}
}
printf("hindi topper is :\n");
printf("%s", s[n].name);
return 0;
}
int english_topper()
{
int n=0;
max=s[0].sub_english ;
for(i=0;i<15;i++)
{
if(max<s[i].sub_english )
{
max=s[i].sub_english ;
n=i;
}
}
printf("english topper is:\n");
printf("%s", s[n].name);
return 0;
}
int computerscience_topper()
{
int n=0;
max=s[0].sub_computerscience ;
for(i=0;i<15;i++)
{
if(max<s[i].sub_computerscience )
{
max=s[i].sub_computerscience;
n=i;
}
}
printf("the computersciencetopper is");
printf("%s",s[n].name);
return 0;
}
0
This is the input I tested the adjusted code with:
hello
1 2 3
hi
3 2 1
yo
1 2 3
hello
1 2 3
hi
3 2 1
yo
1 2 3
hello
1 2 3
hi
3 2 1
yo
1 2 3
hello
1 2 3
hi
3 2 1
yo
1 2 3
hello
1 2 3
hi
3 2 1
yo
1 2 3