當前位置:九游会j9娱乐平台-九游ag登录中心网址 » 編程軟體 » 編程列印以下圖形

編程列印以下圖形-九游会j9娱乐平台

發布時間: 2024-01-18 18:16:57

c語言編程實現:輸出以下圖形

#include"stdio.h"
voidmain(){
inti,j;
for(i=1;i<=3;i ){
for(j=1;j<10-i;j )
printf("40");
for(j=1;j<=2*i-1;j )
printf("52");
printf(" ");}
for(i=2;i>=1;i--){
for(j=1;j<10-i;j )
printf("40");
for(j=1;j<=2*i-1;j )
printf("52");
printf(" ");}}

已經運行過。有什麼問題請留言。

㈡ 編寫程序:列印以下圖形:

main()
{
int i,j,k;
for(i=0;i<=3;i )
{
for(j=0;j<=2-i;j )
printf(" ");
for(k=0;k<2*i;k )
printf("*");
printf("\n");
}
for(i=0;i<=2;i )
{
for(j=0;j<=i;j )
printf(" ");
for(k=0;k<=4-2*i;k )
printf("*");
printf("\n");
}
}再去掉三個for循環就可以了
第二種方法:
最少個數for實現:

[10:33:06@~/c-cpp]$ cat star.c
#include
int main()
{
int n = 0, i, j;
printf("enter an positive odd number: ");
scanf("%d", &n);
int a[n]; /* compile with '-std=c99' */
for (i = 0; i <= n/2; i )
a[i] = a[n-i-1] = i;
for (i = 0; i < n; i ) {
for (j = 0; j < n; j )
printf("%c", a[i] a[j] < n/2 ? ' ' : '*');
printf("\n");
}

return 0;
}
[10:33:15@~/c-cpp]$ gcc --std=c99 star.c
[10:33:23@~/c-cpp]$ ./a.out
enter an positive odd number: 7
*
***
*****
*******
*****
***
*
[10:33:27@~/c-cpp]$ ./a.out
enter an positive odd number: 5
*
***
*****
***
*
[10:33:32@~/c-cpp]$ ./a.out
enter an positive odd number: 3
*
***
*
[10:33:33@~/c-cpp]$ ./a.out
enter an positive odd number: 1
*
[10:33:35@~/c-cpp]$ ./a.out
enter an positive odd number: 17
*
***
*****
*******
*********
***********
*************
***************
*****************
***************
*************
***********
*********
*******
*****
***
*
[10:33:37@~/c-cpp]$

㈢ 用c語言編寫程序,列印以下圖形。。 表示c語言老師講的沒聽懂。。求大神。。。

#include

#include


int main()

{

int k,i,j;

for(i=0;i<4;i )

{

for(k=3;k>i;k--)

printf(" ");

for(j=0;j<2*i 1;j )

printf("*");

printf(" ");

}

for(i=0;i<3;i )

{

for(k=0;k<=i;k )

printf(" ");

for(j=0;j<5-2*i;j )

printf("*");

printf(" ");

}

return 0;

}


兩個循環嵌套,分別是四行正三角和三行倒三角。主要思考【空格】每行循環幾次,【星號】每行循環幾次,這兩個量分別跟【行數】有什麼關系。

熱點內容
發布:2024-01-20 01:08:21 瀏覽:525
發布:2024-01-20 01:07:17 瀏覽:250
愛奇藝正義聯盟為啥不能緩存 發布:2024-01-20 00:52:13 瀏覽:248
caccess查詢資料庫 發布:2024-01-20 00:43:10 瀏覽:769
xp文件夾圖標更改 發布:2024-01-20 00:43:03 瀏覽:19
python和node 發布:2024-01-20 00:37:12 瀏覽:194
android拖拉 發布:2024-01-20 00:00:49 瀏覽:583
少兒編程課程體系介紹 發布:2024-01-20 00:00:48 瀏覽:846
我說你做下載ftp 發布:2024-01-20 00:00:47 瀏覽:8
安卓驅動培訓哪裡好 發布:2024-01-19 23:55:41 瀏覽:987
网站地图