Answer to Question #155456 in C++ for Ejaz

Question #155456

Write a program that Square n numbers & show result in Tabular form(Pass by value, Pass by reference)


1
Expert's answer
2021-01-14T11:37:38-0500
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main () {
  cout << "\n\n========================This program calculate square of N entered numbers========================\n\n";
  int n;
  cout << "Enter n: ";
  cin >> n;
  cout << "Enter numbers: \n";
  int i = 0, length = n;
  int array[n];
  while (n--) {
    int number;
    cin >> number;
    array[i++] = number;
  }
  cout << "Number: ";
  for (i = 0; i < length; i++) {
    cout << setw(6) << array[i] << "  |";
  }
  cout << "\nSquare: ";
  for (i = 0; i < length; i++) {
    cout << setw(6) << pow(array[i], 2) << "  |";
  }
}

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