C++ Program of Sum, Multiplication, Average Program in Array

In this program we will learn how to calculate sum, multiply and average of numbers stored in array.

The code is given below.

//Code Starts

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

  int n,a[n],sum=0,mul=1;

  float avg;

 

  cout<<“Enter Size of Array : “;

  cin>>n;

 

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

  {

    cout<<“Enter Number at “<<i<<” index : “;

    cin>>a[i];

  

    sum=sum+a[i];

    mul=mul*a[i];

  }

 cout<<“Sum = “<<sum<<endl;

 cout<<“Multiplication = “<<mul<<endl;

 avg=sum/n;

 cout<<“Average = “<<avg;

 getch();

}

//Code Ends

OUTPUT:

C++ program of bubble sorting array

In this program we will learn how  to sort elements of array in bubble sorting order.

The code is given below.

//Code starts

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

int a[50],n,i,j,temp;

cout<<“Enter the size of array: “;

cin>>n;

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

{

cout<<“Enter number at index [“<<i<<“] : “;

cin>>a[i];

}

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

{

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

{

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

cout<<“Array after bubble sort:”;

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

cout<<” “<<a[i];

getch();

}

//Code ends

OUTPUT: