0

Write a program to output the following graphics 1 23 456

using for loop c++

8th Oct 2018, 6:29 PM
Gerald Mandengenda
Gerald Mandengenda - avatar
9 ответов
+ 2
#include<iostream> using namespace std; int main() { int y,t; // you need a var that will be // printed at any iteration // his starting value is 1 int s= 1; for( y=1;y<=3;y++){ // dont forget to // increment s at any // iteration for(t=1;t<=y;t++, s++){ // print the var cout<<s; } // at any group we have // to print a space cout<<' '; } return 0; }
8th Oct 2018, 7:27 PM
KrOW
KrOW - avatar
+ 2
Where is your try?
8th Oct 2018, 6:33 PM
KrOW
KrOW - avatar
+ 1
The problem is that you init t var to 1 every time inside nested loop , then every time it print y numbers starting from 1 and its not what you want... You have to use another var inited before entering the outer loop, incremented any nested loop iteration and use it for output... Futhermore dont forget space at end of any inner loop
8th Oct 2018, 6:46 PM
KrOW
KrOW - avatar
+ 1
ma man thanks
9th Oct 2018, 8:36 AM
Gerald Mandengenda
Gerald Mandengenda - avatar
+ 1
Gerald Mandengenda The important is that you have understanded the code 👍
9th Oct 2018, 9:13 AM
KrOW
KrOW - avatar
0
#include<iostream> using namespace std; int main() { int y,t; for( y=1;y<=3;y++) { for(t=1;t<=y;t++) { cout<<t; } } return 0; }
8th Oct 2018, 6:38 PM
Gerald Mandengenda
Gerald Mandengenda - avatar
0
thanks bra lemme try again
8th Oct 2018, 6:48 PM
Gerald Mandengenda
Gerald Mandengenda - avatar
0
You are welcome 😉... And if have some doubt, ask
8th Oct 2018, 6:49 PM
KrOW
KrOW - avatar
0
can you pliz show mi how to edit the program
8th Oct 2018, 6:55 PM
Gerald Mandengenda
Gerald Mandengenda - avatar