7. Write, compile: and run a C++ program to input eight integer numbers into an
ID: 3758846 • Letter: 7
Question
7. Write, compile: and run a C++ program to input eight integer numbers into an array named grade. As each number is input, add the numbers to a total. After all numbers are input, display the numbers and their average. 8. Define an array with a maximum of 20 integer values and fill the array with numbers of your own choosing as in initializers. Then write, compile: and run a C++ program that reads the numbers in the array and places all zero and positive numbers in an array named positive and all negative numbers in an array named negative Finally, have your program display the values in both the positive and negative arrays.Explanation / Answer
7.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[8],i,sum=0;
float av;
for(i=0;i<8;i++)
{
cout<<"Enter no";
cin>>a[i];
sum=sum+a[i];
}
cout<<"Numbers are:"<<endl;
for(i=0;i<8;i++)
{
cout<<a[i]<<endl;
}
cout<<"Sum of elements is "<<sum;
av=sum/8;
cout<<"Average is " <<av;
getch();
}
8.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[20],i, positive[20],negative[20],c=0,d=0;
for(i=0;i<20;i++)
{
cout<<"Enter Number";
cin>>a[i];
if(a[i]>=0)
{
positive[c]=a[i];
c++;
}
else
{
negative[d]=a[i];
d++;
}
}
cout<<"Positive Number are:";
for(i=0;i<c;i++)
{
cout<<" "<<positive[i];
}
cout<<" Negative Number are:";
for(i=0;i<d;i++)
{
cout<<" "<<negative[i];
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.