Basic C++ coding problem The first two sample programs (arrays_1.cpp, arrays_2.c
ID: 3924561 • Letter: B
Question
Basic C++ coding problem
The first two sample programs (arrays_1.cpp, arrays_2.cpp) above should help you on this part. Write a program which declares an array of 6 integers, then prompt the user for 6 values, reads them in from the keyboard, and stores them in an array. You should use a loop to read in your values, as shown in arrays_2.cpp. Using a loop (different from the loop you wrote to read in the data) write them back to the console. Compile, test and run your program. REMEMBER: C++ arrays are indexed from 0 to n-1, not from 1 to n. So your loops should be from i=0 to iExplanation / Answer
ans.1.a)
#include<iostream.h>
#include<conio.h>
main()
{
int a[i];
cout<<"Enter array elements";
int i;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<a[i];
}
int sum=0;
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
cout<<"Sum is";
cout<<sum;
float avg;
avg=sum/n;
cout<<"Average is";
cout<<avg;
for(i=0;i<n;i++)
{
cout<<a[i];
}
for(i=n-1;i>=0;i--)
{
cout<<a[i];
}
getch();
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.