c语言编程 打印图形,菜单包括:矩形,平行四边形,输入图形的行数、列数并输入打印的字符,打印出图形

问题描述:

c语言编程 打印图形,菜单包括:矩形,平行四边形,输入图形的行数、列数并输入打印的字符,打印出图形
1个回答 分类:综合 2014-11-12

问题解答:

我来补答
#include
#define true 1
void print(char cType, int iRow, int iColumn, char cMark)
{
int i,j;

if(cType == 'A')
{
for(i = 0; i < iRow; i++)
{
for(j = 0; j < iColumn; j++)
{
printf("%c ", cMark);
}
printf("\n");
}
}
else if(cType == 'B')
{
for(i = 0; i < iRow; i++)
{
for(j = iRow; j > i; j--)
{
printf(" ");
}
for(j = 0; j < iColumn; j++)
{
printf("%c ", cMark);
}
printf("\n");
}
}
else
{
printf("Error\n");
}
}

int main()
{
int iRow;
int iColumn;
char cType;
char cMark;

while(true)
{
printf("Please select the graph you want to print \nA. Rectangle B. Parallelogram Q. Quit\n");
scanf("%c", &cType);
getchar();
if(cType != 'A' && cType != 'B' && cType != 'Q')
{
printf("\nInput illegal\n\n");
continue;
}
if(cType == 'Q')
{
return 0;
}

printf("Please input the number of rows: ");
scanf("%d", &iRow);
printf("Please input the number of columns: ");
scanf("%d", &iColumn);

printf("Please input the charactor you want to print : ");

getchar();
scanf("%c", &cMark);
getchar();

print(cType, iRow, iColumn, cMark);

}

return 0;
}
 
 
展开全文阅读
剩余:2000