I would like to get an output of the biggest even number. but when i input 1 2 3 (3 scanf) the output is 4.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int ary[100];
int x,y=0;
int amount;
scanf("%d",&amount);fflush(stdin);
for(x=1;x<=amount;x++)
{
scanf("%d",&ary[x]);
if(ary[x]%2==0)
{
if(ary[0]<ary[x])
{
ary[0]=ary[x];
}
}
}
printf("%d",ary[0]);
getchar();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire