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???

Expert's answer

#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";

}

}

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";

}

}

## Comments

## Leave a comment