當前位置:首頁 » 編程語言 » 用c語言列印出矩形圖案
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

用c語言列印出矩形圖案

發布時間: 2023-02-09 15:42:01

『壹』 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;}

『貳』 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語言畫矩形

每行起始和結束字元均是你的第3個參數
矩形第1行和最後一行中間是第3個參數,其他行根據第4個參數決定是空格或者第3個參數
程序可以這樣寫:
...
for ( m=0;m<a;m++ )
{
printf("%c",c); //第1列
if ( m==0 || m==a-1 ) //第1行和最後一行
for ( n=1;n<b-1;n++ ) printf("%c",c);
else //中間的行
for ( n=1;n<b-1;n++ ) if ( d==0 ) printf(" "); else printf("%c",c); //空心或否
printf("%c\n",c); //最後1列
}
或者可以寫:
for ( m=0;m<a;m++ )
{
printf("%c",c); //第1列
if ( m==0 || m==a-1 || d!=0) for ( n=1;n<b-1;n++ ) printf("%c",c);
else for ( n=1;n<b-1;n++ ) printf(" ");
printf("%c\n",c); //最後1列
}

『肆』 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語言做距離屏幕左邊3個字元列印出一個矩形圖案

//可以實現你的功能要求,運行可用
#include <stdio.h>int main(){
int l=20,d=5,wide=3;//矩形的長是l,寬是d,前面空出來的字元個數是wide
for(int j=0;j<d;j++){
for(int i=0;i<wide;i++){
printf(" ");
}//控制列印空格字元個數
for(int k=0;k<l;k++){
printf("*");
}//控制長方形的長
printf("\n");
}//大循環控制長方形的寬

return 0;

}

『陸』 求助 C語言 題目,輸出 以下圖案 方矩形: * * * * * * * * * * * * * * * * * * * * * * * * *

#includ<stdio.h>

intmain(){
inti,j;

for(i=0;i<5;i++){
for(j=0;j<5;j++){
printf("*");
}
//一行列印完成,換行
printf(" ");
}
//全部列印完成
printf(" ");

return0;
}

『柒』 c語言編寫一個矩形圖案 怎麼寫

#include<stdio.h>
int main()
{
int l=3,d=3,wide=5;//矩形的長是l,寬是d,前面空出來的字元個數是wide
for(int j=0;j<d;j++)
{
for(int i=0;i<wide;i++)
{
printf(" ");
}//控制列印空格字元個數
for(int k=0;k<l;k++)
{
printf("*");
}//控制長方形的長
printf("\n");
}//大循環控制長方形的寬
return 0;
}

『捌』 用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語言列印矩形

參考代碼如下:

#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;
}