c - How to make the pyramid (CS50 Mario Program) formed by this code to be right aligned? -
please me create pyramid height "n" print correctly using hashes , spaces right-aligned. have posted code below. program correctly asks user input, doesn't build pyramid right-aligned. if can fix this, please help.
#include <stdio.h> #include <cs50.h> int main(void) { int i=0; int n=0; { printf("height:"); n=getint(); } while (n<0 || n>23); (i=0; i<n; i++) { printf(" "); (int x=0; x<i+2; x++) { printf("#"); } printf("\n"); } return 0; }
inside main loop have:
// instruction printing 1 space // sub loop printing x+1 number of hashes // instruction printing new line
so each time loops round it's correctly drawing hashes , new line not telling draw more 1 space each time unlike subloop hashes instruction doesn't increase each pass.
Comments
Post a Comment