m getting time limit exceeded for the following code:
#include<stdio.h>
int main()
{
int num;
while(scanf("%d",&num)!=42)
printf("%d\n",num);
return 0;
}
m getting time limit exceeded for the following code:
#include<stdio.h>
int main()
{
int num;
while(scanf("%d",&num)!=42)
printf("%d\n",num);
return 0;
}
scanf doesnt return the number you input.
this is your corrected code…
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
while(num!=42)
{
printf("%d\n",num);
scanf("%d",&num);
}
return 0;
}
scanf returns the number of fresh inputs it has taken…like if u take 1 i/p it returns 1…eg…
scanf("%d",n);
this will store the i/p in n and return 1
similarly…
scanf("%d %d",&n,&n1);
this will store the respective ips and return 2…as the number of inputs taken are 2…
if u call the fxn and it encounters EOF(end of file) then it will return -1…with the previous number as it was in that var…you can see this link…LINK…hope this helps…