How can I write a function in C that will take in a number, n, and will display one * on the first line, then one more each line until it displays a line with n *'s.
Example: draw(4) would display:
*
**
***
****
My main problem is getting it to print a new line at the appropriate time, and not after each *
C Programming?
void printStars(int n){
   if (n %26lt; 1) return;
    for(int i = 1; i %26lt;= n; ++i){
        for(int j = 1; j %26lt;= i; ++j){
          printf('*');
          }
     printf('\n');
    }
}
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment