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

  打印平行四边形,输入图形的行数、列数并输入打印的字符,打印出图形。如:行数为5行,字符为*。~

#include
void main()
{
int i,a,n,j,k;
char c;
printf("行数:");
scanf("%d",&a);
printf("列数:");
scanf("%d",&n);
getchar();
printf("字符:");
scanf("%c",&c);
for(i=1;i<=n;i++)
{
for(k=1;k<=n-i;k++)
printf(" ");
for(j=1;j<=n;j++)
printf("%c",c);
printf("
");
}
}

我可以给你写出代码,
#include
int main()
{
int i,j,k,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=i-n;j++)
printf(" ");
for(k=1;k<=2*i-1;k++)
printf("*");
printf("
");
}
这是等腰三角形;
int i,j,n;
scanf("%d"&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
printf("*");
}
printf("
");
}
这是直角三角形的;用两个for,一个外循环,一个内循环。这是基础,加油!

#include<stdio.h>
#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;
}

相关兴趣推荐

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网