Problem : Rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.
Example
Input : 1 2 88 42 99
Output : 1 2 88
My solution :
#include<stdio.h>
int main()
{
int i;
scanf("%d",&i);
while(i!=42)
{
printf("%d",i);
scanf("%d",&i);
}
return 0;
}
Correct Solution :
#include <stdio.h>
int main( void ) {
int i;
while( 1 ) {
scanf( "%d", &i );
if( i == 42 ) break;
printf( "%d\n", i );
}
return 0;
}
Both the programs end if the input is 42, then what is the difference between the two?
EDIT : I just realized that this should have been posted at codereview.stackexchange.com Admins please do the needful.