㈠ c语言打印矩形
参考代码如下:
#include<stdio.h>
intmain()
{
intm,n,i,j;
scanf("%d%d",&m,&n);
if(m>80||n>80)
return0;
for(i=1;i<=m;++i){
for(j=1;j<=n;++j)
printf("%c",i%2==1?'c':'d');
printf(" ");
}
return0;
}
㈡ c程序中,如何让字符按照实心矩形输出,调用函数
在C语言程序中,只要输入实心矩形的边长以及构成矩形的字符,就可以使用2重循环,把这个矩形进行输出。
int n,i,j;
char c;
scanf("%d %c",&n,&c);
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
printf("%c",c);
printf("\n");
}
输入数据时,表示边长的数字和字符之间留一个空格。
㈢ C语言如何矩形输出
是基础练习吧?
横列像这样输出
pintf("------------------------\n")
纵列就麻烦点,这样输出,你可以连续打多行,也可以用循环来多次输出
pintf("| |\n")
如果要做的好点,伪代码如下,CODE:
for(循环宽度次数){
printf("-")
}
printf("\n")//换行
for(循环高度次数){
printf("|")
for(循环(宽度-2)次数){
printf(" ")
}
printf("|")
printf("\n")//换行
}
for(循环宽度次数){
printf("-")
}
printf("\n")//换行
==================================================
晕……
如此啊
伪代码:
for(i=0;i<20;i++){
printf(i)
if(i==5)
printf("\n")//当i为5的时候换行
}
㈣ c语言编程 打印图形,菜单包括:矩形,平行四边形,输入图形的行数、列数并输入打印的字符,打印出图形
#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;
}
㈤ 用c语言打印矩形
#include<stdio.h>
intmain()
{
inti,j,n;
printf("请输入n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=1;j<=n;j++)
{
printf("%4d",j+i*n);
}
printf(" ");
}
return0;
}
㈥ 用C语言程序打印一个空心的矩形的问题
#include<stdio.h>
int main()
{
int i,j,m,n;
printf("输入矩形的常和宽:\n");
scanf("%ld",&m);
scanf("%ld",&n);
for(i=0;i<m;i++)printf("-");
printf("\n");
for(j=0;j<n;j++)
{
printf("|");
for(i=0;i<(m-2);i++)printf(" ");
printf("|\n");
}
for(i=0;i<m;i++)printf("-");
return 0;
}
这个能显示
㈦ c语言题目 打印出10*10的矩形,并输出以下形状
//看着这个图形比较有意思,于是写了一下。调试通过,没有问题,欢迎采纳。
#include<stdio.h>
int main()
{
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(i==0||i==9)
printf("* ");
else
if(j==0||j==9||j==(10-i-1)||j==i)
printf("* ");
else
printf(" ");
}
putchar('\n');
}
getchar();
return 0;
}
㈧ C语言打印矩形
可以,任何使用for的循环都可以使用while来替代#include int main() { int y = 0; while(y < 4) { int x = 0; while(x < 8) { if (0 == x || 0 == y || 7 == x || 3 == y) { printf("*"); } else { printf(" "); } x++; } printf("\n"); y++; } return 0;}