C++ program to find average of list of numbers entered through keyboard

C++ program to find average of list of numbers entered through keyboard

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr(); //to clear the screen
int i,n,x,sum=0;

cout<<“How many numbers?”;
cin>>n;

for(i=1;i<=n;++i)
{
cout<<“nEnter number “<<i<<“: “;
cin>>x;
sum+=x;
}

x=sum/n;
cout<<“nnAverage=”<<x;
getch(); //to stop the screen
}

One thought on “C++ program to find average of list of numbers entered through keyboard

  1. mark

    I am trying to find the average of positive numbers entered by a user using break in c++, but am not getting it right. What is my problem?
    Q: @ Write a program to find the average of n positive numbers entered by a user. But if a negative number is entered, the average of the positive numbers is displayed and end the program.
    Here is the code:
    #include
    using namesapce std;
    int main()
    {float num,average,sum=0;
    int i,n;
    cout<>n;
    for(i=1;1<=n;++1)
    {cout<<"enter n:"<>num;
    if(num<0.0){break;
    }
    average=sum/(i-1);
    cout<<"average="<<average;
    return 0;
    }}

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *