Tuesday 3 July 2012

Program to display a pattern in form of reverse stairs in C


Code - 


//_________Program to display a pattern in form of reverse stairs________________

/*_________Sample Pattern_______________________

pattern -
4444
333
22
1

1, 2, 3, 4 represent the coloumn number in a row.....Number of rows will be inputted by the user___*/

//___________________Import Header Files__________________

#include<stdio.h>

#include<conio.h>

int main()

  //__________Main Function from where the program execution starts____________

{
int row = 0, coloumn = 0, user_input;

//____Variable declaration and initialization________


printf("\n\n\t     _________Program will display the pattern_________");

printf("\n\n Enter the total number of coloumns required - ");

//________Prompting the user to enter the total number of rows______

scanf("%d", &user_input);

//____Reading the user input and storing it in variable user_input___

printf("\n\n Pattern - \n\n");

for(coloumn = user_input; coloumn >= 1 ; coloumn--)

       //_____Looping construct from user_input to 1____
{
printf("\t"); //_______Display 5 spaces_____

for(row = 1; row <= coloumn; row++)
{
printf(" %d",coloumn);

//_____Display the coloumn number (total coloumns in a row)________

                }
printf("\n");


//_____Taking the cursor to the next line_______

}


getch();

return 0;
}

Follow Us on Facebook - Assignment Hub

No comments:

Post a Comment