Trying to space out each of my output lines (creating a flipped triangle)

44 Views Asked by At

I'm trying to use a for loop to add a space to the beginning of my output for every line. For every line, it will add more space between as it goes through each line to get the flipped triangle.

My code

#include <stdio.h>
#include <math.h>

// compiler issue on 2nd digit 

int main(){

long long number;

printf("Enter a number\n");
printf("Enter your number = ");
scanf("%lld", &number);


    for(int j=1; j<= (log10(number)+1); j++){
    for(int i=1; i<= (log10(number)+1) - (j-1); i++){
       printf("%d   ", (number%((int)pow(10, i)))/(int)pow(10, i-1));
    
   }
       printf("\n");

   }

   
   return 0;
}

My output:

Enter a number
Enter your number = 12345
5   4   3   2   1
5   4   3   2
5   4   3
5   4
5   

What I'm trying to output:

Enter a number
Enter your number = 12345
 5   4   3   2   1
   5   4   3   2
     5   4   3
       5   4
         5   

A sample program as what I had in mind

int main()
{
    int l;
    for(l=0; l<3; l++){
        printf("%*s Moving\n", l, "");
        
    }
    
    return 0;
}
0

There are 0 best solutions below