Revision as of 19:43, 13 May 2024 by Admin (Created page with "Write a function that outputs a right-side-up triangle of height ''n'' and width ''2n-1''; the output for ''n = 6'' would be: <pre> * *** ***** ******* ********* *********** </pre>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
May 13'24

Exercise

Write a function that outputs a right-side-up triangle of height n and width 2n-1; the output for n = 6 would be:

     *
    ***
   *****
  *******
 *********
***********
May 13'24

One possible solution: void right_side_up(int n) {

   int x,y;
   for (y= 1; y <= n; y++)
   {
       for (x= 0; x < n-y; x++)
           putchar(' ');
       for (x= (n-y); x < (n-y)+(2*y-1); x++)
           putchar('*');
       putchar('\n');
   }

}

Another solution:

#include

int main(void) {

 int n;
 scanf("%d",&n);
 for(int i=0;i

}

00