printf usage
Go to solution
Solved by 79wjd,
7 minutes ago, dirtbikerxz said:so the way i have my program setup it gives me the position number fore each. like in h = 10. what is the easiest way to generate 9 spaces before that? oh (h position - 1) spaces
A while loop would be the simplest, albeit least elegant form.
Something like this, although, I would try and come up with something less cumbersome.
Spoiler
int H; T; diff;
//H and T are set
if(H > T){
diff = H-T;
for(int i=0; i<T; i++)
printf(" ");
printf("T");
for(int i=0; i<diff; i++)
printf(" ");
printf("H\n");
} else {
diff = T-H;
for(int i=0; i<H; i++)
printf(" ");
printf("H");
for(int i=0; i<diff; i++)
printf(" ");
printf("T\n");
}
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now