Draw a empty stairs patten using nested loop in c++
#include <iostream>
using namespace std;
void stairs(int n)
{
for (int i = 1; i <= n; i++) {
int k = (i % 2 != 0) ? i + 1 : i;
for (int j = 0; j < k; j++)
cout << " * ";
cout << endl;
}
}
int main()
{
int st = 10;
stairs(st);
return 0;
}
Comments
Leave a comment