Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Calculate Average Using Arrays

 C++ Program to Calculate Average of n number, using array.This program takes n number of element from user(where, n is specified by user), stores data in an array and calculates the average of those numbers.This program calculates the average if the number of data are from 1 to 100. If user enters value of n above 100 or below 100 then, while loop is executed which asks user to enter value of n until it is between 1 and 100.

Source Code:-

#include <iostream.h>
#include <conio.h>

int main()
{   clrscr();
    int n, i;
    float num[100], sum=0.0, average;
    cout<<"Program to calculate Average using array by-Tarun Rawat\n\n";
    cout<<"Enter the numbers of data : ";
    cin>>n;
    while (n>100 || n<=0)
    {   cout<<"Error! number should in range of (1 to 100).\n";
    cout<<"Enter the number again : ";
    cin>>n;
    }
   for(i=0; i<n; ++i)
   {
      cout<<i+1<<" Enter number : ";
      cin>>num[i];
      sum+=num[i];
   }
   average=sum/n;
   cout<<"Average = "<<average;
getch();
}

No comments:

Post a Comment

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)