In: Computer Science
Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, and that terminates when it reads an integer that is not positive. The values should be separated by single blank spaces. Declare any variables that are needed. (In C language please).
// C code
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int main()
{
int number;
// loop that reads positive integers from standard
input, printing out those values that are greater than 100,
// and that terminates when it reads an integer that
is not positive
while(1)
{
// read positive integers from
standard input
printf("Enter number: ");
scanf("%d",&number);
// terminates when it reads an
integer that is not positive
if(number <= 0)
break;
// printing out those values
that are greater than 100,
if(number > 100)
{
printf("Number:
%d\n",number);
}
}
return 0;
}
/*
output:
Enter number: 101
Number: 101
Enter number: 45
Enter number: 344
Number: 344
Enter number: 22
Enter number: 133
Number: 133
Enter number: 211
Number: 211
Enter number: -1
*/