當前位置:首頁 » 編程軟體 » 編程列印以下圖案

編程列印以下圖案

發布時間: 2022-02-10 08:21:17

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

#include <stdio.h>

#include <stdlib.h>


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;

}


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

『貳』 java編程:編寫程序列印下列圖案

class For
{
public static void main(String[] args)
{

for(int i=4;i>0;i--)
{
//左邊空格
for(int j=1;j<=7-i;j++)
System.out.print(" ");
//空格後面的*
for(int s=1;s<=i*2-1;s++)
System.out.print("*");
//回車
System.out.println();
}

for(int i=2;i<=4;i++)
{
for(int j=1;j<=7-i;j++)
System.out.print(" ");
for(int s=1;s<=i*2-1;s++)
System.out.print("*");
System.out.println();
}
}
}
第二種方法 不過 這個空格沒弄 你可以自己加上
class For
{

public static void main(String[] args)
{

for(int x=7;x>0;x--)
{
if(x%2==1)
{

for(int y=0;y<x;y++)
{
System.out.print("*");
}
System.out.println();

}
}
for(int x=3;x<9;x++)
{
if(x%2==1)
{
for(int y=0;y<x;y++)
{
System.out.print("*");
}
System.out.println();
}
}

『叄』 編寫一程序,列印出以下圖案:

main()
{
int
m,n;
for
(m=1;m<7;m+=2)
{
for
(n=1;n<=m;n++)
printf("*");
printf("\n");
}
for
(m=7;m>0;m-=2)
{
for
(n=1;n<=m;n++)
printf("*");
printf("\n");
}
}
參數寫錯了.不好意思.呵呵~現在對了.如果不對是你機器問題了...

『肆』 編寫程序列印出以下圖案

for(i=5;i>0;i--)
{
for(k=1;k<6-i;k++)
printf(" ");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");
}

『伍』 編程列印以下圖案

最簡單的辦法
cout<<"A"<<endl;
cout<<"BBB"<<endl;
cout<<"CCCCC"<<endl;
。。。。。。。。。。
這個辦法有點非主流,不過能達到目的。

『陸』 編程,列印以下圖案

如果是c的話,最簡單的版本是:

#include<stdio.h>

int main(){

printf("* ");

printf("* * * ");

printf("* * * * ");

return 0;

}

『柒』 編寫程序:列印以下圖形:

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 <stdio.h>
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語言教程

『玖』 編程列印以下圖形

復制下來,編譯一下吧,TC2下編譯通過,和你的要求一樣,是一個三角形的星圖案.
main()
{
int i,j,k;
for(i=0;i<3;++i)
{
for(j=2-i;j>0;--j)
printf(" ");
for(k=0;k<i+1;++k)
printf("* ");
printf("\n");
}
}

『拾』 java 編寫程序列印下面的圖案

publicclass${

publicstaticvoidmain(String[]args){

intsize=5;

for(inti=0;i<size;i++){

//空格
for(intj=0;j<size-i-1;j++){
System.out.print("");
}

//星號
for(intj=0;j<=i;j++){
System.out.print("*");
}

System.out.println();
}
}
}

熱點內容
網站搭建伺服器搭建 發布:2025-03-16 10:33:27 瀏覽:795
游戲目錄在哪裡安卓 發布:2025-03-16 10:33:19 瀏覽:467
婉兒腳本 發布:2025-03-16 10:19:33 瀏覽:580
c語言ftp下載文件 發布:2025-03-16 10:05:02 瀏覽:307
手機帳戶密碼怎麼找回密碼 發布:2025-03-16 10:02:10 瀏覽:706
c語言位段的使用 發布:2025-03-16 10:00:38 瀏覽:572
象山編程 發布:2025-03-16 09:38:41 瀏覽:927
綠點掌知識薪資密碼是多少 發布:2025-03-16 09:37:05 瀏覽:597
osu安卓版怎麼 發布:2025-03-16 09:37:05 瀏覽:153
python編程編程第三版 發布:2025-03-16 09:29:56 瀏覽:968