Sum and Average of Float Array in C Plus Plus

By | July 12, 2019

Task: Sum and Average of Float Array in C Plus Plus

The Source Code of C++ Program Sum and Average of Float Array

// Write a C++ Program using Arrays
// to input n numbers in array
// then Calculate and Print sum & average
// of all numbers in array
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	int n,i;
	float arr[100],sum,average;
	cout<<"Enter Number of values:";
	cin>>n;
	//cout<<"Now Enter "<<n<<" numbers:"<<endl;
	sum=0;
	for(i=0;i<n;i++)
	{
		cout<<"Enter Number "<<(i+1)<<": ";
		cin>>arr[i];
		sum=sum+arr[i];
	}
	average=sum/n;
	cout<<"Sum of all numbers in Array = "<<sum<<endl;
	cout<<"Average of All Numbers in Array = "<<average<<endl;
	return 0;
}

Output of a Sample Run of the Program

Enter Number of values:10
Enter Number 1: 10
Enter Number 2: 20
Enter Number 3: 30
Enter Number 4: 40
Enter Number 5: 11
Enter Number 6: 500
Enter Number 7: 600
Enter Number 8: 5
Enter Number 9: 3
Enter Number 10: 2
Sum of all numbers in Array = 1221
Average of All Numbers in Array = 122.1

--------------------------------
Process exited after 90.16 seconds with return value 0
Press any key to continue . . .

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *