+ 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

31st Oct 2020, 4:07 PM
Carlye
18 ответов
+ 8
for(int i=0;i<10;++i) { cout<<i<<" "; cout<<i*i<<" "; } if u want the output downwards use endl.
31st Oct 2020, 4:12 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
Where's ur try/code
31st Oct 2020, 4:09 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
Carlye if u want to program nos ranging from 1 to 10 ,then why r u taking user input.
31st Oct 2020, 4:23 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
Martin Taylor yeah 😂😅
31st Oct 2020, 4:34 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 5
Okk Your code is corrected. Check it: https://code.sololearn.com/cPCHplYj0mnj/?ref=app
31st Oct 2020, 4:28 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 5
Carlye Do u check the code I have corrected for u. Was that ur aim
31st Oct 2020, 4:35 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 5
Macross-Plus Yeah i knw tht. That is the least Carlye can do to get his desired output!!
1st Nov 2020, 4:40 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 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.
1st Nov 2020, 3:14 PM
Nikhil
+ 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.
31st Oct 2020, 11:44 PM
Macross-Plus
Macross-Plus - avatar
0
need user to input number in the range
31st Oct 2020, 4:25 PM
Carlye
0
and then output that number and the numer squared next to it
31st Oct 2020, 4:26 PM
Carlye
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.
31st Oct 2020, 4:28 PM
Carlye
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
31st Oct 2020, 4:33 PM
Carlye
0
i think i got it thanks!
31st Oct 2020, 4:39 PM
Carlye
0
For(i=1;i<=10;i++) Sqr=i*i; Cout<<i<<sqr<<" ";
2nd Nov 2020, 5:17 AM
shubhankar jain
0
Write a sample program in C++ using the if-else conditional structure. Make sure that the syntax you are using is being discuss?
2nd Nov 2020, 7:07 AM
Ailamae Parayon
Ailamae Parayon - avatar
0
How do I write moving shapes in c++???
2nd Nov 2020, 9:23 AM
Dhanabakiyam Selvaraj
Dhanabakiyam Selvaraj - avatar