0
Write a program to output the following graphics 1 23 456
using for loop c++
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;
}
+ 2
Where is your try?
+ 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
+ 1
ma man thanks
+ 1
Gerald Mandengenda The important is that you have understanded the code 👍
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;
}
0
thanks bra lemme try again
0
You are welcome 😉... And if have some doubt, ask
0
can you pliz show mi how to edit the program