Write a C++ program that creates an array “A” having 5 elements (in the main function). Then, the
program asks the user to enter values in this array. After that, the program should replace each array
element which is divisible by 3 with new value (by adding 1 to it). In the end, the main program (“main”)
shows the updated array elements in ascending order.
#include <iostream>
using namespace std;
int main()
{
const int N = 5;
int A[N];
cout << "Please, enter 5 values: ";
for (int i = 0; i < N; i++)
{
cin >> A[i];
}
cout << "Your array: ";
for (int i = 0; i < N; i++)
{
cout<<A[i]<<" ";
}
for (int i = 0; i < N; i++)
{
if (A[i] % 3 == 0)
A[i] += 1;
}
cout << endl << "Resulting array: ";
for (int i = 0; i < N; i++)
{
cout << A[i] << " ";
}
}
Comments
Leave a comment