Print out diagonal

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
int main(void){
    int input , i;
    scanf("%d", &input);
    do{
        for (i=input-1;i!=0;i--){
            printf(" ");
        }
    printf("*\n");
    input -= 1;
    }while(input>0);

}



Is there a way to make above code shorter?
Well, I will print an asterisk.

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main( void )
{
   int n;
   
   scanf( "%d", &n );
   
   while ( n ) printf( "%*c\n", n--, '*' );
}
Last edited on
Topic archived. No new replies allowed.