google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a C++ program to find the sum and average of n number of the array - 2nd puc computer science

Write a C++ program to find the sum and average of n number of the array

 /*Write a C++ program to find the sum and average of n number of the array.*/

#include<iostream.h>

#include<conio.h>

void main( )

{

int a[50], i, n, sum; float avg;

clrscr();

cout<<"How many elements?"<<endl;

cin>>n;

cout<<"Enter the elements:"<<endl;

for(i=0; i<n; i++)

cin>>a[i];

sum = 0;

for(i=0; i<n; i++)

sum = sum + a[i];

avg=(float) sum / n;

cout<<"Sum = "<<sum<<endl;

cout<<"Average = "<<avg<<endl;

getch( );

}

Write a C++ program to find the sum and average of n number of the array Write a C++ program to find the sum and average of n number of the array Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.