Description
Create a C source le and copy the following function de nition into it:
void triangle(unsigned width)
{ unsigned i, j;
i = 0; while (i <= width) { j = 0; while (j < i) { putchar(‘*’);
++j; } putchar(‘\n’);
++i;
}
}
Add a main function that calls triangle() with a number of your choosing, and complete the source le such that you can compile and execute your program.
- (3 points) Rewrite triangle() to use for loops instead of while loops.
- (3 points) Write a version of triangle() called v_triangle() that prints the triangle upside-down, with themaximum length line at the top.
https://sakai.rutgers.edu/portal/site/f55b6385-2252-4de5-a0e1-6b8fe3227eeb/tool/5b736e6b-8b6b-4963-af7f-8ab2a622a40c?panel=Main 1/2 1/24/22, 2:39 PM sakai.rutgers.edu : CS 214 — Spring 2021 : Assignments
- (3 points) Write a version of triangle() called h_triangle() that prints the triangle such that the right side isvertical. That is, h_triangle(5) should print
*****
****
***
**
*
- (3 points) Create a program that can print any of the three triangles described above, based on itscommand-line arguments. Use atoi() to convert the rst argument from a string to an integer: this will be the width of the triangle. If no second argument is provided, use triangle(). If the second argument is “v”, use v_triangle(). If it is “h”, use h_triangle().
Your program should return EXIT_SUCCESS from main for normal operation, or EXIT_FAILURE if given incorrect/inappropriate arguments.






