19.2k views
3 votes
Write a complete program that declares an integer variable, readsa value from the keyboard into that variable, and writes tostandard output the variable's value, twice the value, and thesquare of the value, separated by spaces.

User Jakob Gade
by
7.6k points

1 Answer

6 votes

Answer:

// here is code in c++.

// include headers

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable

int n;

cout<<"Enter a number:";

// read the number

cin>>n;

// Calculate twice of number

int twice=2*n;

// Calculate square of number

int sqr=n*n;

// print number, twice and square separated by space

cout<<n<<" "<<twice<<" "<<sqr<<endl;

return 0;

}

Step-by-step explanation:

Read an integer from user and assign it to variable "n".Calculate its twice

by multiply "n" with 2 and assign it to "twice".Then Calculate its square by

multiply n*n.Print the number, its twice and its square separated by a space.

Output:

Enter a number:5

5 10 25

User Nekto
by
7.6k points