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

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows