Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

the language is c do not use arrays The program first reads an integer n from th

ID: 668574 • Letter: T

Question


the language is c

do not use arrays

The program first reads an integer n from the input.It displays a message simply stating the value of n.It then displays an “up” staircase with n stepsThen it displays a “down” staircase with n stepsAnd finally, it displays an “up-down” staircase composed of n levels:  up followed by down (see example below).

In the example below, assume that n=3 has been read from the input.

Number of stairs: 3

up:

      X

  XX

 XXX

down:

 X

 XX

 XXX

up-down:

     X

  XXX

 XXXXX

goodbye.

Explanation / Answer

#include<stdio.h>
#include<conio.h>

void main()
{
   int n,c=0,i,j,l=2,k;
   clrscr();


   printf("Enter value for n");
   scanf("%d",&n);
  
   printf("Up: ");
   l=n-1;
   for(i=1;i<=n;i++)
   {
       for(k=1;k<=l;k++)
       {
           printf(" ");
       }
       for(j=1;j<=i;j++)
       {
           printf("%d",c);
       }
       l--;
       printf(" ");
   }
   printf("Down: ");
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=i;j++)
       {
           printf("%d",c);
       }
       printf(" ");
   }
   printf("Up-Down:");
   l=n-1;
   for(i=1;i<=n;i=i+2)
   {
       for(k=1;k<=l;k++)
       {
           printf(" ");
       }
       for(j=1;j<=i;j++)
       {
           printf("%d",c);
       }
       l--;
       printf(" ");
   }
   printf(" Good Bye");
   getch();
}