I am having a brain shock right now so I wanted to ask very simple question.
Currenly, I am trying to print out starts like this
when input is 7 , the output is
*
**
*
**
*
**
*
and here my code is , it prints 14 times instead of 7 or when I put N/2 it doesnt print the odd number.
#include <iostream>
using namespace std;
int main () {
int N;
cout << " Please enter N " ;
cin >> N;
for (int i = 0; i < N ; i++) {
cout << "*" << endl;
for (int j = 0; j < 2; j++) {
cout << "*" ;
}
cout << endl;
}
}
For each
Nyou are printing two lines, with single*and another with two*. Instead just print single line with either one or two star based on the line is odd or even.(Untested code)