Answer to Question #227471 in C++ for Johnnie

Question #227471
Write a C++ program that creates a one dimensional array of length n. Your program should
read five integers into the array from the keyboard and perform a traversal operation of
squaring all even elements of the array.
1
Expert's answer
2021-08-19T03:22:22-0400
#include <iostream>
using namespace std;




int main(){
   // we declare an one-dimensional array that accepts n length
     int n=5;
     int arr[n];
 // we should enter the elements of array from keyboard
    cout << "Enter 5 integer numbers: " << endl;
    for (int i = 0; i < n; i++){
        cin >> arr[i];}
    cout << "The entered array is : " <<endl;
    for (int i = 0; i < n; i++) {
        cout << arr[i] << " \n";
    if (arr[i] % 2 == 0)
    cout<<"The sqaure of " <<arr[i]<<" is : "<<arr[i]*arr[i]<<"\n";
    }


   return 0;
}

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