Thursday, February 4, 2016

Staircase - Hacker Rank Solution

Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example?

Input
You are given an integer N depicting the height of the staircase.
Output
Print a staircase of height N that consists of # symbols and spaces. For example for N=6, here's a staircase of that height:
     #
    ##
   ###
  ####
 #####
######
Note: The last line has 0 spaces before it.
----------------------------------------------------------------------------------------------------------------

 Staircase - Hacker Rank Solution 

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

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0; i<n;++i){    
        for (int j= 0;j<((n-i)-1);++j){
            printf(" ");
        }
        for (int k=0;k<(i+1);++k){
            printf("#");
        }
        printf("\n");
    }

    return 0;
}

 Staircase - Hacker Rank Solution  

-----------------------------------------------------------------------------------------------------------------------------

 

Powered by Blogger.