Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Write a C++ Program to Find Sum and Average of n numbers using for loop.



Write a C++ Program to Find Sum and Average of n numbers using for loop...

Answer / hr

Solution:
/* C++ Program to Find Sum and Average of n numbers using for loop */
#include<iostream>
using namespace std;
int main()
{
int i,n,x,sum=0;
float avg;
cout<<"How many numbers u want to enter :: ";
cin>>n;
for(i=1;i<=n;++i)
{
cout<<"
Enter number "<<i<<" :: ";
cin>>x;
sum+=x;
}
avg=(float)sum/(float)n;
cout<<"

Sum of "<<n<<" Numbers :: "<<sum;
cout<<"

Average of "<<n<<" Numbers :: "<<avg;
cout<<"
";
return 0;
}
Output:
/* C++ Program to Find Sum and Average of n numbers using for loop */
How many numbers u want to enter :: 6
Enter number 1 :: 1
Enter number 2 :: 2
Enter number 3 :: 3
Enter number 4 :: 4
Enter number 5 :: 5
Enter number 6 :: 6
Sum of 6 Numbers :: 21
Average of 6 Numbers :: 3.5
Process returned 0

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

Explain the importance of method overloading in C++?

0 Answers   Akamai Technologies, Infogain,


Explain the FOR loop with a help of a code.

0 Answers   Accenture,


Discuss the role of C++ shorthands.

0 Answers   Adobe,


What are the costs and benefits of using exceptions?

0 Answers   Amazon,


What does it mean to declare a function or variable as static?

0 Answers   Amazon,


Question on Copy constructor.

0 Answers   Alter,


Without using third variable write a code to swap two numbers.

0 Answers   Accenture,


What is latest update of C++ ?

0 Answers   Adobe,


Difference between function overloading and function overriding.

0 Answers   Alter,


What is the difference between public, private, and protected inheritance?

0 Answers   Amazon,


What are string library functions(syntax).

0 Answers   Accenture,


C++ supports multiple inheritance. What is the “diamond problem” that can occur with multiple inheritance? Give an example.

0 Answers  


Categories