-
Notifications
You must be signed in to change notification settings - Fork 0
/
numberCounter2.c
56 lines (41 loc) · 1.32 KB
/
numberCounter2.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
int main(void){
int PositiveNumber = 0;
int sumOfNumber =0;
float average=0.0;
int numberOfTerm;
int smallestNumber, largestNumber;
int counter;
do {
numberOfTerm = 0;
printf("Welcome\n");
printf("Enter a negative integer to end\n");
scanf("%d", &PositiveNumber);
smallestNumber=PositiveNumber;
largestNumber=PositiveNumber;
sumOfNumber =PositiveNumber;
while(PositiveNumber > 0){
printf("Enter an integer: \n");
scanf("%d", &PositiveNumber);
if(smallestNumber>PositiveNumber && PositiveNumber >0){
smallestNumber=PositiveNumber;
}
if(largestNumber<PositiveNumber){
largestNumber=PositiveNumber;
}
if (PositiveNumber >0){
sumOfNumber = sumOfNumber+PositiveNumber;
}
numberOfTerm++;
}
printf("The smallest number is: %d\n", smallestNumber);
printf("The biggest number is: %d\n", largestNumber);
printf("The sum of number is: %d\n", sumOfNumber);
average = (float) sumOfNumber/numberOfTerm;
printf("The average of number is: %f\n",average);
printf("Would you like to run the program again (1 for yes, 0 for no)?");
scanf("%d",&counter );
} while (counter==1);
return 0;
}