Answer to Question #274452 in C++ for Sihle

Question #274452

TASKS

• Task 1: Install Microsoft Visual Studio C++ 2022 Community IDE on your laptop.

• Task 2: Write a program that stores the first N square integers (starting from 1) in a single array. You should allow the value N to be entered from the command line and use dynamic allocation to create the array.

Print the array to the screen at the end of your program. Modify your program so that the array can be extended by a number M also entered from the command line and then print it again. Sample output is shown below.

Enter N: 5 1 4 9 16 25

Enter M: 3 1 4 9 16 25 36 49 64



1
Expert's answer
2021-12-03T07:45:12-0500
#include <iostream>
#include <math.h>
using namespace std;


void perfectSquares(int n)
{
    int i=1;
    int count=0;
    while(true){
        if (sqrt(i) == (int)sqrt(i)){
            cout << i << " ";
            count++;
        }
        if(count==n){
            break;
        }
       i++;     
    }
}
int main()
{
    int N;
    cout<<"\nEnter N: ";
    cin>>N;
    perfectSquares(N);
    int M;
    cout<<"\nEnter M: ";
    cin>>M;
    perfectSquares(N+M);
    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