Write a C++ Program to Find Sum and Average of n numbers using for loop.
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 |
Explain encapsulation in C++.
Describe the different styles of function prototypes in C++.
Identify the errors in the following program. #include <iostream> using namespace std; void main() { int i=5; while(i) { switch(i) { default: case 4: case 5: break; case 1: continue; case 2: case 3: break; } i-; } }
what do you mean by exception handling in C++?
Difference between function overloading and function overriding.
What is an algorithm (in terms of the STL/C++ standard library)?
Name the operators that cannot be overloaded.
What is constant keyword in C++? Illustrate its various uses.
0 Answers Akamai Technologies, Infogain,
What is an abstract class?
Do you know about Agilent PRECOMPILERS. ?
What is function overloading and operator overloading in C++?
C++ supports multiple inheritance. What is the “diamond problem” that can occur with multiple inheritance? Give an example.