I\'m having a little trouble with the following arrays: I will award the 1,500 p
ID: 3556519 • Letter: I
Question
I'm having a little trouble with the following arrays: I will award the 1,500 points for the proper code.
Create three arrays of type int and initialize them to 0:
Programmatically fill the second array with 100 odd numbers starting at 1
i.e. {1,3,5,7...........}
Programmaticly fill the first array with 100 even numbers starting at 0
i.e. {0,2,4,6..........}
Programmaticly set the third array elements equal to the sum of the first two arrays elements
i.e. {1,5,9,13.........}
Output the three individual arrays AND the SUM i.e. 1+5+9+13......... Of the 100 elements of the third array.
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int a1[100]={0},a2[100]={0},a3[100]={0},i,j;
for(i=0;i<100;i++)
a1[i]=2*i+1;
for(i=0;i<100;i++)
a2[i]=2*i;
for(i=0;i<100;i++)
a3[i]=a1[i]+a2[i];
cout<<endl<<"First array : "<<endl;
for(i=0;i<100;i++)
cout<<a1[i]<<" ";
cout<<endl<<"Second array : "<<endl;
for(i=0;i<100;i++)
cout<<a2[i]<<" ";
int sum=0;
cout<<endl<<"Third array : "<<endl;
for(i=0;i<100;i++)
{
cout<<a3[i]<<" ";
sum+=a3[i];
}
cout<<endl<<"SUM : "<<sum<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.