In: Computer Science
(C++)
Write a program that prints a table in the following format given a "x" read from the keyboard. For example, if x is 4, it prints out
0 0
1 1
2 4
3 9
4 16
To avoid mismatch, put 8 white spaces between two numbers.
Below is the c++ program which takes an integer x and displays the output as mentioned above - (after the code, attached the sample output images of random input tests) -
#include <iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter x: ";
cin>>x;
cout<<endl;
for(int i=0;i<=x;i++)
{
cout<<i<<" "<<i*i<<endl;
}
return 0;
}
Code image :
Output sample-1 :
Sample output-2 :