Monday, July 2, 2018

C program to draw staircase

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

void staircase(int n) {
    
    char c='#';
    int x=n-1,y=1;

    for(int i=0;i<n;i++)
    {
        for(int j=x;j>0;j--)
      {
        printf(" ");

      }

        x--;

        for(int k=0;k<y;k++)
        {
            printf("%c",c);

        }
            y++;
            if(y==n+1)
            exit(0);
         printf("\n");
    }

}

int main() {
    int n;
    scanf("%i", &n);
    staircase(n);
    return 0;
}






No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...