0
Only getting ***** of following code instead of getting right triangle of *..kindly debug it
#include <iostream> using namespace std; int main() { int i,j; j=1; i=1; do { cout<<"*"; i++; } while(i<=5); do { j=1; cout<<"\n"; j++; } while(j<=i); return 0; }
4 ответов
+ 4
You have two separate loops, instead of a nested loop (loop within a loop). Did you try putting the second loop within the first loop? Can you do it? :>
+ 1
Hey!
You have to encapsulate the inner do while loop inside the outer loop, then print new line in the outer and the * in the inner and increment the j in the outer loop not in the inner!
+ 1
Solved my prob...
Thanks for everyone for helping..
Below is final working code
////////////////////////////////////////
#include <iostream>
using namespace std;
int main()
{
int i=1;
do
{
int j=1;
do
{
cout<<"*";
j++;
}
while(j<=i);
cout<<"\n";
i++;
}
while (i<=5);
cout<<"\n";
return 0;
}
- 1
No i cant nested two loops as me totaly new to loop...
Kindly make changes in code