Home / Expert Answers / Computer Science / how-do-i-program-this-in-c-the-box-is-an-example-of-the-ran-code-program-stairs-filename-stair-pa683

(Solved): How do I program this in C. The box is an example of the ran code. Program: stairs Filename: stair ...



Program: stairs
Filename: stairs.c
Behavior:
- The program first reads a non-negative integer \( n \) from the input.
- It th

How do I program this in C. The box is an example of the ran code.

Program: stairs Filename: stairs.c Behavior: - The program first reads a non-negative integer \( n \) from the input. - It then displays an "up" staircase with n steps - Then it displays a "down" staircase with n steps - And finally, it displays an "up-down" staircase composed of \( \mathrm{n} \) levels: up followed by down (see example below). Two examples below (one for \( \mathrm{n}=3 \) and one for \( \mathrm{n}=0 \) ) : \( \$ \)./stairs Enter number of stairs: 3 up: \[ \begin{array}{l} x \\ x x \\ x x x \\ \text { down: } \\ \text { x } \\ \text { xx } \\ \text { xxx } \\ \text { up-down: } \\ \text { X } \\ \text { Xxx } \\ \text { xxxxx } \\ \text { \$./stairs } \end{array} \] Enter number of stairs: 0 up: down: up-down: \( \$ \) Error Handling: if the user input cannot be parsed as an non-negative integer, the program simply prints "INVALID INPUT" and terminates immediately (it does not re-prompt the user or anything like that).


We have an Answer from Expert

View Expert Answer

Expert Answer


C PROGRAM: stairs.c #include int main(){ int n; printf("Enter number of stairs: "); int flag = scanf("%d", &n); // Input n non negative inetger int space, x, i; if(flag == 1 && n >=0){ // check
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe