Computer Science, asked by keerthijoy902, 1 month ago

write a C++ program to find the average of n natural numbers using for loop​

Answers

Answered by Anonymous
0

ANSWER ~

/*  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<<"\nEnter number "<<i<<" :: ";

       cin>>x;

       sum+=x;

   }

   avg=(float)sum/(float)n;

   cout<<"\n\nSum of "<<n<<" Numbers :: "<<sum;

   cout<<"\n\nAverage of "<<n<<" Numbers :: "<<avg;

   cout<<"\n";

   return 0;

Similar questions