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 integerthat is not positive. The values should be separated by single blank spaces. Declare any variables that are needed.
PLEASE ANSWER IN C
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
#include <stdio.h>
int main() {
// declare variables
int i,num;
int arr[1000];
int index=0;
// prompt the user to enter numbers
printf("Enter numbers (negative number to stop):
\n");
while(1)
{
// read that number
scanf("%d",&num);
if(num<0)
{
// if negative break
break;
}
if(num>100)
{
// if value greater than 100, add it to array
arr[index]=num;
index++;
}
}
// print all the numbers greater than 100
printf("Numbers greater than 100 are:\n");
for(i=0;i<index;i++)
printf("%d ",arr[i]);
return 0;
}
=====================
SCREENSHOT: