+ 1
C++ program
How do I write a program with a loop that will output the numbers 1-10 and the number squared. all in a loop. Output like this: 1 1 2 4 3 9 until 10 100 Thanks
18 Answers
+ 8
for(int i=0;i<10;++i)
{ cout<<i<<" ";
cout<<i*i<<" ";
}
if u want the output downwards use endl.
+ 7
Where's ur try/code
+ 7
Carlye if u want to program nos ranging from 1 to 10 ,then why r u taking user input.
+ 7
Martin Taylor yeah 😂😅
+ 5
Okk Your code is corrected.
Check it:
https://code.sololearn.com/cPCHplYj0mnj/?ref=app
+ 5
Carlye Do u check the code I have corrected for u. Was that ur aim
+ 5
Macross-Plus Yeah i knw tht.
That is the least Carlye can do to get his desired output!!
+ 3
It is very simple .
Just iterate through the numbers 1 to 10 using a loop and print the number and its square.
Here we go .
for(int i=1; i<=10;i++)
{
cout<<i<<" "<<i*i<<" ";
}
The space is to separate the numbers .
Hope it is helpful.
Thank you.
+ 1
Alphin K Sajan
The code you corrected for Carlye outputs just the input number squared and not the number itself. It also gives the output even if the number input is not within the range 1-10.
0
need user to input number in the range
0
and then output that number and the numer squared next to it
0
i guess i dont need userinput just need to get number to then output that number and then square it to output that number.
0
trying to get number from the range 1-10 and when that is inputed then that number gets squared and both are outputes next to each other
0
i think i got it thanks!
0
For(i=1;i<=10;i++)
Sqr=i*i;
Cout<<i<<sqr<<" ";
0
Write a sample program in C++ using the if-else conditional structure. Make sure that the syntax you are using is being discuss?
0
How do I write moving shapes in c++???