Staircase
5 more points to get your next star!
Rank: 1519966|Points: 95/100
Problem Solving
Problem
Submissions
Leaderboard
Discussions
Editorial
Staircase detail
This is a staircase of size :
Its base and height are both equal to . It is drawn using # symbols and spaces. The last line is not preceded by any spaces.
Write a program that prints a staircase of size .
Function Description
Complete the staircase function in the editor below.
staircase has the following parameter(s):
int n: an integer
Print
Print a staircase as described above.
Input Format
A single integer, , denoting the size of the staircase.
Constraints
.
Output Format
Print a staircase of size using # symbols and spaces.
Note: The last line must have spaces in it.
Sample Input
6
Sample Output
#
##
Explanation
The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of .
在这里我说一下啊,在传统的编译器是不能在定义数组的时候用变量的啊,只能用常量,除非你是C++,我这是在Xcode上写的,在HackerRank上的编译器也是完全没有问题
#include<stdio.h>
int main ()
{
int n , m ;
scanf ("%d",&n) ;
m = n ;
char arr[n][m] ;//注意这里的定义,在VC++6.0上是不行的
for ( int i = 0 ; i < n ; i ++ )//因为我不会在初始赋值的时候把一个字符赋值给所有的数组元素的方法,所以只能遍历单个输入
{
for ( int j = 0 ; j < m ; j ++ )
{
arr[i][j] = '#' ;
}
}
// {
// for ( int i = 0 ; i < n ; i ++ )
// {
// for ( int j = 0 ; j < m ; j ++ )
// {
// printf ("%c",arr[i][j]);
// }
// printf ("\n");
// }
// }
for ( int i = 0 ; i < n ; i ++ )
{
for ( int j = 0 ; j < m ; j ++ )
{
if ( (i + j) <= (n - 2) && (i + j) >= 0 )
{
arr[i][j] = ' ' ;
}
}
}
for ( int i = 0 ; i < n ; i ++ )
{
for ( int j = 0 ; j < m ; j ++ )
{
printf ("%c",arr[i][j]);
}
printf ("\n");
}
printf ("\n");
return 0;
}