#3
by box » 1年前
こんなことがしたいんかな?
コード:
#include <stdio.h>
void getShapeAndHeight(int *s, int *h)
{
do {
printf("形は?(1:○, 2:△, 3:□)"), scanf("%d", s);
} while (!(1 <= *s && *s <= 3));
do {
printf("段数は?(1から20)"), scanf("%d", h);
} while (!(1 <= *h && *h <= 20));
}
void drawPyramid(int n, int h)
{
char *s[] = { "", "○", "△", "□" };
int x, y;
for (y = 0; y > -h; y--) {
for (x = -h + 1; x <= h - 1; x++) {
printf("%s", (y <= x && y <= -x) ? s[n] : " ");
}
putchar('\n');
}
}
int main(void)
{
int shape, height;
getShapeAndHeight(&shape, &height);
drawPyramid(shape, height);
return 0;
}
こんなことがしたいんかな?
[code]
#include <stdio.h>
void getShapeAndHeight(int *s, int *h)
{
do {
printf("形は?(1:○, 2:△, 3:□)"), scanf("%d", s);
} while (!(1 <= *s && *s <= 3));
do {
printf("段数は?(1から20)"), scanf("%d", h);
} while (!(1 <= *h && *h <= 20));
}
void drawPyramid(int n, int h)
{
char *s[] = { "", "○", "△", "□" };
int x, y;
for (y = 0; y > -h; y--) {
for (x = -h + 1; x <= h - 1; x++) {
printf("%s", (y <= x && y <= -x) ? s[n] : " ");
}
putchar('\n');
}
}
int main(void)
{
int shape, height;
getShapeAndHeight(&shape, &height);
drawPyramid(shape, height);
return 0;
}
[/code]