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

Mention the default functions in C++, how would you detect that error has occurred inside the constructor and destructor.

0 Answers   Adobe,


What is an abstract class in C++

0 Answers   SwanSoft Technologies,


What is the difference between creating an object, using 'new' and using 'malloc'?

3 Answers   HFG, Siemens,


What are the major differences between C and C++?

0 Answers   Amazon,


What is function overloading and operator overloading in C++?

0 Answers   IBS, TCS,


How does stack look in function calls? Write a recursive function call, how will the stack look like?

0 Answers   Adobe,


What is Advantage and Use of THIS pointer in C++ – Scenarios?

0 Answers  


How does stack look in function calls? When does stack overflow? What can you do to remedy it?

0 Answers   Adobe,


What is the 4 difference between delete[] and delete?

0 Answers   Alter,


Can we call a virtual function from a constructor?

1 Answers  


What are the fundamental features of an object-oriented language?

0 Answers   Accenture,


What are the costs and benefits of using exceptions?

0 Answers   Amazon,


Categories