Smallest Numbers of Notes | CodeChef

I need help. It is showing wrong answer.
#include <stdio.h>
int main(void) {
int t, n,a=0,b=0,c=0,d=0,e=0, f=0, count=0;
scanf(“%d”,&t);
while(t–)
{
scanf(“%d”,&n);
while(n>=100)
{
a=n/100;
n=n%100;
}
while(n>=50)
{
b=n/50;
n=n%50;
}
while(n>=10)
{
c=n/10;
n=n%10;
}
while(n>=5)
{
d=n/5;
n=n%5;
}
while(n>=2)
{
e=n/2;
n=n%2;
}
f=n;
count=a+b+c+d+e+f;
printf(“%d\n”,count);
}
return 0;
}

Try the test case

2
4
100

Always define your variables in the lowest scope possible, in this case, inside the while loop.

1 Like

Hey, Thanks.