i want to write a program to rank the score there's my attempt:
int i,j,s[5][2],tmp,p;
for(i=0;i<5;i++)
{
printf("plz input student numder:\n");
scanf("%d",&s[i][0]);
printf("score:\n");
scanf("%d",&s[i][1]);
}
for(p=0;p<5;p++)
{
for(i=p+1;i<5;i++)
{
if(s[i][1]>s[p][1])
{
tmp=s[p][1];
s[p][1]=s[i][1];
s[i][1]=tmp;
j=s[p][0];
s[p][0]=s[i][0];
s[i][0]=j;
}
}
}
for(i=0;i<5;i++)
{
printf("rank%d %d %d\n",i+1,s[i][0],s[i][1]);
}
return 0;
but the output is:
plz input student numder:
123202033
score:
65
plz input student numder:
125425152
score:
56
plz input student numder:
102323122
score:
98
plz input student numder:
102325244
score:
75
plz input student numder:
210232322
score:
45
rank1 21426 98
rank2 23548 75
rank3 -5647 65
rank4 -10752 56
rank5 -7166 45
鼢
Dt
?? ?0??????"屪?@ ? @ ? ? ?
9"x噈惄u v0??~ "?
You are giving very large input in the student id
plz input student numder: 123202033
That is not corresponding to valid range an integer
that's why it is giving output in negatives