0
Draw this pattern in one loop
* ** *** **** *****
8 Respostas
+ 3
Does this work for you?
#include<bits/stdc++.h>
using namespace std;
void printPattern(int n) {
int curr_star = 0;
for (int line_no = 1; line_no <= n;) {
if (curr_star < line_no) {
cout << "* ";
curr_star++;
continue;
}
else {
cout << "\n";
line_no++;
curr_star = 0;
}
}
}
int main()
{
printPattern(7);
return 0;
}
https://code.sololearn.com/czqse90iUD1N/?ref=app
+ 2
Not in C. Python FTW!
for i in range(1, 6):
print("*" * i)
+ 2
I am totally agree with niawahta. Use only one loop and you can use conditions.
+ 2
woa
+ 1
but I want ans in c
+ 1
But I don't think it's possible.
+ 1
for(unsigned i = 0; i < 6; ++i){
for(unsigned j = 0; j <= i; ++j)
putchar('*');
putchar('\n');
}
Everything is possible in C :D
+ 1
@Baptiste E. Prunier
The question says one loop. I know it's quite easy with a nested for loop, that's pretty common.