problem:
write a program that reads in a list of integer values , entered one per line, and outputs the average of the integer entered. the program asks the user how many numbers will be on the list and uses this value to control the loop that reads in the numbers. this program need not echo the input
1
Expert's answer
2012-08-21T10:11:55-0400
#include <iostream.h>
int i, num, arr[100], *a; double avg=0;
void main(){ a=arr; cout<<"how many numbers will be on the list? "; cin>>num; cout<<"enter "<<num<<" numbers, please:\n"; for(i=0;i<num;i++) { cin>>*a; a++; } for(i=0;i<num;i++) avg+=arr[i]; avg = avg/num; cout<<"the average is "<<avg<<"\n"; }
Comments
Leave a comment