Anda di halaman 1dari 1

1 /*Name:Mtthew Bloomfield

2 Date:1/11/17
3 desc:program to accept a set of postive integers and print their average and their max*/
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <conio.h>
7
8 int main()
9 {
10 int count;
11 float num, sum, largestNum, avg;
12
13 count=-1;
14 sum=0;
15 largestNum=0;
16
17
18 printf("\nEnter positive integers. End entry process by entering '0'\n");
19 do
20 {
21 scanf("%f", &num);
22
23 if (num<0)
24 {
25 printf("\nEnter a positive number.\n");
26 scanf("%f", num);
27
28 }
29 if (num>largestNum)
30 {
31 largestNum=num;
32 }
33 count=count+1;
34 sum=sum+num;
35 }
36 while(num!=0);
37 avg=0;
38 avg=sum/count;
39
40 printf("\nLargest number in set: %d", largestNum);
41 printf("\nAverage of set of numbers: %.2f", avg);
42 getch();
43
44 }

Anda mungkin juga menyukai