USING C++ Write a program which declares both an input array of integers and an
ID: 643832 • Letter: U
Question
USING C++
Write a program which declares both an input array of integers and an output arrays of integers The code should get input from the user to initialize the input array of integers then the code should assign to the output array of integers the values of the input array of integers where each corresponding value is the sum of the first and last digit of the value in the input array assuming each value in the input array is 2 or more digits in length. input array: output array: Test with arrays of size 6 And the above input.Explanation / Answer
#include <iostream>
using namespace std;
int main ()
{
int array1[6];
int array2[6];
int num1, num2, temp;
cout << "Enter 6 integers: " << endl;
for (int i = 0; i < 6; i++)
{
cin >> array1[i];
}
for (int i = 0; i < 6; i++)
{
num1 = 0;
num2 = 0;
if (array1[i] < 10)
array2[i] = array1[i];
else
{
temp = array1[i];
num1 = array1[i] % 10;
do
{
num2 = temp % 10;
temp = temp / 10;
} while (temp > 0);
array2[i] = num1 + num2;
}
}
cout << "----------------------------" << endl;
cout << "Array 1:" << endl;
for (int i = 0; i < 6; i++)
{
cout << array1[i] << " ";
}
cout << endl << "----------------------------" << endl;
cout << "Array 2:" << endl;
for (int i = 0; i < 6; i++)
{
cout << array2[i] << " ";
}
cout << endl << "----------------------------" << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.