I created a finished code for a mario problem set.
Want to know if I understand the last if statement correctly.
If the user enters 4, the code will print out 4 columns with hashes, because it uses the remaining rows to print a blank space on each column.
Just wanted to know, if my point of view is correct.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int r, c, ans;
printf("Value between 0 and 9\n");
scanf("%d", &ans);
while(ans < 1 || ans > 8)
{
printf("INVALID REPSONSE PLEASE TRY AGAIN\n");
scanf("%d", &ans);
}
if(ans > 0 || ans <= 8)
{
for(r = 0; r <= ans; r++)
{
for(c = 0; c < ans; c++)
{
if(c >= ans - r)
{
printf("#");
}else
{
printf(" ");
}
}
printf("\n");
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire