In: Computer Science
Goal: To bring together everything you've learned about repetition, relational operators, and input validation and show your mastery of these concepts.
You are to write a program that will allow a user to enter as many
numbers as they want (one number at a time and all numbers must be
greater than zero). You must have a way for the user to stop
entering values. Once the user stops, you will immediately display
the following:
An IPO or Flowchart for the problem.
A test case sheet that shows 3 sets of input data, and the
expected results of running the
program for each set of input data.
C Code
Program code:
#include<stdio.h>
int main()
{
int
array[1000],min=1000,max=0,count=0,i,val,ch;
float sum=0,average;
while(1)
{
printf("Enter a
number:");
scanf("%d",&val);
if(val>0)
{
array[count]=val;
count++;
}
else
printf("Negative values are not allowed...\n");
printf("Do you want to
continue(1/0):");
scanf("%d",&ch);
if(ch==0)
break;
}
for(i=0;i<count;i++)
{
if(max<array[i])
max=array[i];
if(min>array[i])
min=array[i];
sum=sum+array[i];
}
average=sum/count;
printf("\nThe lowest number was:%d",min);
printf("\nThe highest number was:%d",max);
printf("\nThe number of values entered
was:%d",count);
printf("\nThe average of numbers
was:%f",average);
}
Output:
Testcase-1:
Testcase-2:
Testcase-3: