Program to Display Sum and Average of Numbers in C++.

In this Program, user provide input (numbers) to know the sum and average of entered data .

 

 

Let’s open turboC++ and write the following code.

 

 

//Code

 

 

//Add preprocessor

 

#include<conio.h>

#include<iostream.h>

void main()

{

    float sum=0,avg=0,i=0;

    float a[10];

 

// Clear Screen

 clrscr();

 

    cout<<”enter all numbers:”;

    for(i=0;i<10;i++)

{

    cin>>a[i];

}

    for(i=0;i<10;i++)

{

    sum=sum+a[i];

}

    avg=sum/i;

    cout<<”\n Sum:=”<<sum;

    cout<<”\n Average :=”<<avg;

    getch();

}

 

 

 

Step 2: Run the program and see output.

 

 

Output:

 

 

 

output

 

Happy Coding.

 

 

 

 

 

Tags: , ,