Question #1337

Write a c++ program to accept 5 number usin while and print their sum then print the fifth number and second number and print if second is less or bigger of equal to fifth.

Expert's answer

#include <iostream>

using namespace std;

int main()

{

int i=0,sum=0;

int a[5];

cout<<"Enter five numbers\n";

while(i!=5)

{

& cin>>a[i];

& sum=sum+a[i];

& i++;

}

cout<<"\nSum equals& "<<sum<<endl;

cout<<"Fifth number equqls quot;<<a[4]<<endl;

cout<<"Second number equals& quot;<<a[1]<<endl;

if(a[1]<a[4]) cout<<"Second number is less then fifth\n";

if(a[1]>a[4]) cout<<"Second number is bigger then fifth\n";

if(a[1]==a[4]) cout<<"Second number is equal fifth\n";

system("pause");

return 0;

}

using namespace std;

int main()

{

int i=0,sum=0;

int a[5];

cout<<"Enter five numbers\n";

while(i!=5)

{

& cin>>a[i];

& sum=sum+a[i];

& i++;

}

cout<<"\nSum equals& "<<sum<<endl;

cout<<"Fifth number equqls quot;<<a[4]<<endl;

cout<<"Second number equals& quot;<<a[1]<<endl;

if(a[1]<a[4]) cout<<"Second number is less then fifth\n";

if(a[1]>a[4]) cout<<"Second number is bigger then fifth\n";

if(a[1]==a[4]) cout<<"Second number is equal fifth\n";

system("pause");

return 0;

}

## Comments

## Leave a comment