Problem Definition:
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 code:
here the while loop is not breaking. So, how will i come to know that the input is over?
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 code:
Code:
#include<stdio.h>
void main()
{
int nomore,i,j,output[100],number;
nomore=5;
i=0;
while(scanf("%d",&number))
{
if(number==42)
{
nomore=0;
}
if(nomore!=0)
{
output[i]=number;
i++;
}
}
for(j=0;j<i;j++)
{
printf("%d\n",output[j]);
}
}
Comment