-
Notifications
You must be signed in to change notification settings - Fork 18
/
assignment7.c
39 lines (29 loc) · 927 Bytes
/
assignment7.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<stdio.h>
#include<stdlib.h>
main() {
int userNumber = 0, sum = 0, count = 0, highNumber = 0, lowNumber = 0;
double average;
printf("enter a number greater than 0:(enter -1 to stop)\n");
scanf_s("%i", &userNumber);
highNumber = userNumber;
lowNumber = userNumber;
while (userNumber != -1)
{
if (userNumber > lowNumber && userNumber > highNumber) {
highNumber = userNumber;
}
else if (userNumber < lowNumber)
lowNumber = userNumber;
count = count + 1;
sum = sum + userNumber;
printf("Enter a number:(-1 to stop)\n");
scanf_s("%i", &userNumber);
}
average = (double)sum / count;
printf("the sum is : %i\n", sum);
printf("%i numbers were input \n", count);
printf("the average is %.2lf\n", average);
printf("the highest number entered was : %i\n", highNumber);
printf("the lowest number entered was: %i\n", lowNumber);
system("pause");
}