Revision as of 19:43, 13 May 2024 by Admin (Created page with "Write a function that outputs a sideways triangle of height ''2n-1'' and width ''n'', so the output for ''n = 4'' would be: <pre> * ** *** **** *** ** * </pre>")
May 13'24
Exercise
Write a function that outputs a sideways triangle of height 2n-1 and width n, so the output for n = 4 would be:
* ** *** **** *** ** *
May 13'24
One possible solution:
#include
int n; scanf("%d",&n); for(int i=0;i
0;i--) { for(int j=0;j
}
or like this (all math)
void sideways(int n) {
int i=0,j=0; for(i=1;i<2*n;i++){ for(j=1;j<=(n-(abs(n-i)));j++){printf("*"); } printf("\n");
}
}