116k views
4 votes
Write code that causes a "triangle" of asterisks of size n to be output to the screen. specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consisting of three, etc. the last line should consist of n asterisks. thus, for example, if n has value 3, the output of your code should be

User Corbfon
by
8.0k points

1 Answer

4 votes
like this
#include <stdio.h>void pa(int n){ if(!n){ printf("\\");return;}printf("*");pa(n-1);}void lines(int n){if(!n) return;lines(n-1);pa(n);}int main(void){lines(5);return 0;}
User Pandora
by
7.9k points