Answer to Question #28935 in C++ for lava

Question #28935
write program that declares three integers arrays whith 5 element each ,of which two of them thei element are entered by user. then the program add corresponding element of the two array and put them in the third array out put it???
1
Expert's answer
2013-04-23T09:17:01-0400
#include <iostream>

int main()
{
//Declare three arrays:
int firstArray[5];
int secondArray[5];
int thirdArray[5];

int i = 0;

// Use for construction to get integers from user:
std::cout << "Enter first array( 5 elements ):\n";
for( i = 0; i < 5; ++i )
{
std::cin >> firstArray[i];
}

std::cout << "Enter second array( 5 elements ):\n";
for( i = 0; i < 5; ++i )
{
std::cin >> secondArray[i];
}

//calculate sum of corresponding elements of arrays

for( i = 0; i < 5; ++i )
{
thirdArray[i] = firstArray[i] + secondArray[i];
}

//show result:
for( i = 0; i < 5; ++i )
{
std::cout << "Sum[" << i << "]=" << thirdArray[i] << "\n";
}



}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS