whats wrong with this code ? for "Life,the Universe and Everything" Question

#include <stdio.h>

int main(void) {
int n ;
while((n!=42)&&(n<100)){
scanf("\n%d",&n);
printf("%d",n);
}
return 0;
}

when input is 42 you should not print 42 but your program is printing 42 and then terminating thats all and take care of ā€œ\nā€ after printing o/p.

use while(1){scanf("\n%d",&n); if(n==42)break; printf("%d\n",n);} This will work.

1 Like

how can you write \n in scanf? @filmwalams

I think this code will work for you

include <stdio.h>
int main()
{
int n ;
scanf("%d",&n);
while((n!=42)&&(n<100))
{
printf("%d \n",n);
}
return 0;
}