Answer to Question #331319 in C++ for Zaki

Question #331319

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.

1
Expert's answer
2022-04-20T12:40:31-0400
#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] << " ";
	}
}





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
New on Blog
APPROVED BY CLIENTS