I have a simple question . Why the first program don't work and return me 0 but the second where if go into another if works ? It wont go down and check the next if ?
#include <stdio.h>
int main ()
{
int m,n,tmp,i;
int nnumber=0,numbermin=9999999;
scanf("%d %d",&m,&n);
for(i=m;i<=n;i++)
{
tmp=i;
while (tmp > 0 && (tmp % 10) % 2 == 0)
{
tmp/=10;
}
if (tmp == 0){ // This don't work i as want from this if to go down there and check the next if
i only got 0 at the printf("%d" , numbermin);
nnumber=i;
}
if(nnumber<numbermin)
{
numbermin=nnumber;
}
}
if(nnumber==0)
printf("NO");
else
printf("%d",numbermin);
}
And the code that runs good .
#include <stdio.h>
int main ()
{
int m,n,tmp,i;
int nnumber=0,numbermin=9999999;
scanf("%d %d",&m,&n);
for(i=m;i<=n;i++)
{
tmp=i;
while (tmp > 0 && (tmp % 10) % 2 == 0)
{
tmp/=10;
}
if (tmp == 0){
nnumber=i;
if(nnumber<numbermin)
{
numbermin=nnumber;// But this work perfect i want to know why the first ex didn't work ?
}
}
}
if(nnumber==0)
printf("NO");
else
printf("%d",numbermin);
}
Why only the second one work good but the first don't ?
Aucun commentaire:
Enregistrer un commentaire