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

What do you by Function Overloading in C++?

0 Answers   Akamai Technologies, Infogain,


What is a COPY CONSTRUCTOR and when is it called?

0 Answers   IBS,


Discuss about iteration statements in C++ .

0 Answers   Agilent,


What is meant by exit controlled loop?

0 Answers   Adobe,


What are the different scope C++ provide ?

0 Answers   Amdocs,


What is conversion constructor in C++

0 Answers   TCS,


What is the difference between member functions and static member functions?

0 Answers   Alter,


To solve the 8 Queens problem, which algorithm is used?

0 Answers   Accenture,


what is a pragma in C++?

0 Answers   Aspire,


In C++ what is a vtable and how does it work?

0 Answers   Agilent,


What is Boyce Codd Normal form?

0 Answers   IBS,


What is the difference between an ARRAY and a LIST in C++?

1 Answers   IBS, TCS,


Categories