當前位置:首頁 » 編程語言 » c語言玫瑰花
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言玫瑰花

發布時間: 2022-01-14 02:32:38

A. c語言中什麼是玫瑰花數

c語言中的玫瑰花數是指一個四位數等於它的各數位上的數字的四次方和。

c語言介紹;C語言是一門通用計算機編程語言,應用廣泛,C語言的設計目標是提供一種能以簡易的方式編譯,產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

B. c語言編寫程序 水仙花數 玫瑰花數

1
#include <stdio.h>
#include <stdlib.h>
int flower(int n)
{
int i, j, k;
i = n % 10;
j = n / 10 % 10;
k = n / 100;
if (i*i*i + j*j*j + k*k*k == n)
return 1;
else
return 0;
}
int main(void)
{
int i;
for (i = 100; i < 1000; i++)
{
if (flower(i) == 1)
printf("%d ", i);
}
return 0;
}
2.
#include <stdio.h>
#include <stdlib.h>
int rose(int n)
{
int i, j, k,m;
i = n % 10;
j = n / 10 % 10;
k = n / 100%10;
m = n / 1000;
if (i*i*i*i + j*j*j*j + k*k*k*k+m*m*m*m == n)
return 1;
else
return 0;
}
int main(void)
{
int i;
for (i = 1000; i < 10000; i++)
{
if (rose(i) == 1)
printf("%d ", i);
}
return 0;
}

C. 你是不是有999玫瑰C語言版源代碼能給我嗎

#include <dos.h>
#include <graphics.h>
#include <math.h>
/*玫瑰花*/
#define FNX(x) (int)(xo+(x)*1.0)
#define FNY(y) (int)(getmaxy()-(yo+(y)*1.0))
#define FNX2(phi) cos(phi)*ac-sin(phi)*bs
#define FNY2(phi) cos(phi)*as+sin(phi)*bc

/*畫旋轉的橢圓*/
void elli(int xo,int yo,int a,int b,double theta)
{
int i;
double da,c,s,ac,as,bc,bs,xf,yf,phi,x,y;
theta=theta*0.01745;
da=3*0.1745;
c=cos(theta);
s=sin(theta);
ac=a*c;as=a*s;
bc=b*c;bs=b*s;
x=FNX2(0);
y=FNY2(0);
moveto(FNX(x),FNY(y));
for(i=1;i<=360;i++)
{
phi=i*da;
xf=x*cos(phi)*0.1;
yf=b*sin(phi)*0.1;
x=FNX2(phi);
y=FNY2(phi);
lineto(FNX(x),FNY(y));
}
}

/*花*/
void hua(int x,int y)
{
register i;
/*畫粉紅色玫瑰*/
setcolor(12);
arc(x+65,y-60,150,350,8);
arc(x+66,y-54,300,470,8);
arc(x+65,y-56,30,230,10);
arc(x+64,y-57,300,490,17);
ellipse(x+73,y-30,250,450,27,40);
ellipse(x+59,y-30,100,290,27,40);
ellipse(x+65,y-40,140,270,20,30);
setfillstyle(SOLID_FILL,5);
floodfill(x+65,y-20,12);
/*畫紅色玫瑰*/
arc(x,y,150,350,12);
arc(x+1,y+8,280,470,12);
arc(x,y+2,30,230,16);
arc(x,y+3,80,240,28);
arc(x+2,y+8,180,330,22);
arc(x-2,y+2,310,460,25);
ellipse(x-12,y+30,120,300,30,40);
ellipse(x+10,y+28,250,423,30,42);
ellipse(x-4,y+10,290,393,30,40);
setfillstyle(SOLID_FILL,4);
floodfill(x+5,y+31,12);
/*畫紫色花骨朵*/
ellipse(x+120,y+5,0,360,15,25);
setfillstyle(SOLID_FILL,1);
floodfill(x+120,y,12);
/*畫黃色花骨朵*/
ellipse(x-70,y+10,0,360,14,20);
setfillstyle(SOLID_FILL,14);
floodfill(x-70,y+10,12);
setcolor(10);
/*畫紅花花萼*/
ellipse(x-15,y+32,190,310,30,35);
ellipse(x+16,y+32,235,355,26,35);
ellipse(x,y+35,190,350,43,50);
arc(x,y+82,190,350,6);
setfillstyle(SOLID_FILL,2);
floodfill(x,y+75,10);
/*畫粉花花萼*/
ellipse(x+50,y-48,190,320,22,50);
ellipse(x+80,y-48,220,350,22,50);
ellipse(x+65,y-28,180,360,36,50);
floodfill(x+65,y+18,10);
/*畫主枝*/
for(i=0;i<3;i++ )
{
ellipse(x-98,y+100+i,255,371,100,80);
ellipse(x-20,y+30+i,260,358,140,140);
ellipse(x+224,y+20+i,180,218,160,140);
}
/*畫側枝*/
ellipse(x+70,y+34,180,233,140,140);
ellipse(x,y+40,205,255,100,120);
ellipse(x+135,y-30,209,249,72,120);
ellipse(x,y+20,263,301,100,120);
ellipse(x+85,y-10,278,305,100,120);
ellipse(x+100,y-62,282,308,90,120);
ellipse(x-50,y-10,277,314,30,120);
ellipse(x+70,y+80,222,266,52,120);
ellipse(x-60,y-45,229,266,52,120);
ellipse(x+79,y-45,229,266,52,120);
ellipse(x+84,y,224,273,52,120);
ellipse(x+110,y+40,240,282,100,120);
/*畫紫花骨朵花萼*/
ellipse(x+120,y-6,200,340,17,25);
ellipse(x+120,y+7,160,380,17,27);
floodfill(x+122,y+30,10);
/*畫黃花骨朵花萼*/
ellipse(x-70,y+15,140,390,17,20);
ellipse(x-75,y-10,205,340,10,30);
ellipse(x-60,y-10,195,340,5,30);
floodfill(x-70,y+32,10);
/*畫葉*/
/*畫右邊的葉子*/
elli(x+168,y+282,10,20,-40);
elli(x+160,y+252,8,16,260);
elli(x+145,y+270,8,16,-15);
elli(x+156,y+224,10,20,-45);
elli(x+150,y+200,8,16,270);
elli(x+135,y+220,8,16,-10);
elli(x+146,y+144,8,16,-80);
elli(x+130,y+130,6,12,235);
elli(x+125,y+154,7,14,-10);
elli(x+78,y+98,6,12,-90);
elli(x+60,y+90,5,10,180);
elli(x+70,y+109,5,10,-45);
/*畫左邊的葉子*/
elli(x-125,y+270,12,24,60);
elli(x-95,y+270,10,20,10);
elli(x-110,y+245,10,20,90);
elli(x-105,y+220,10,20,45);
elli(x-100,y+190,8,16,135);
elli(x-75,y+210,8,16,-45);
/*畫中間的葉子*/
elli(x+65,y+190,10,20,-45);
elli(x+40,y+185,8,16,0);
elli(x+55,y+165,8,16,90);
}

/*主程序*/
main()
{
int driver=VGA,mode=VGAHI;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"C:\TC");
cleardevice();
hua(450,90);
setcolor(2);
rectangle(0,0,639,479);
getch();
closegraph();
}

D. 四葉玫瑰數c語言怎麼編程

#include <iostream>
#include <cmath>
using namespace std;
void getRoseNum(int lower,int upper);
bool isRoseNum(int n);
void main()
{
int upper,lower;
cout<<"請輸入下界:"<<endl;
cin>>lower;
cout<<"請輸入上界:"<<endl;
cin>>upper;
cout<<"所有玫瑰花數:"
getRoseNum(lower,upper);

}
void getRoseNum(int lower,int upper)
{
if((lower<1000)||(upper>9999))
{
cout<<"上下界錯誤!"<<endl; return;
}
for (int i=lower;i<=upper;i++)
{
if (isRoseNum(i))
{
cout<<i<<endl;
}
}
}
bool isRoseNum(int n)
{
char a[5]={'0'};//這里改一下就行了,不然會溢出
itoa(n,a,10);
int sum=0;
for (int i=0;i<4;i++)
sum+=pow((double)(a[i]-48),4);
if (n==sum) return true;
return false;
}

E. 輸出1000到9999之間的四葉玫瑰數,用C語言的知識回答

可以寫成調用函數
#include<stdio.h>
void rose(int n)
{int a,b,c,d;
a=n/1000;
b=n/100%10;
c=n/10%10;
d=n%10;
if(a*a*a*a+b*b*b*b+c*c*c*c+d*d*d*d==n)
printf("%d\t",n);
}
main()
{
int i;
for(i=1000;i<=9999;i++)
rose(i);
}
方法比較笨,但更容易理解。望樓主採納。。。

F. C語言編程

#include<stdio.h>
#include <math.h>
void abb(int a)
{
int m,n,p,q;
int x,y,z,s;
m=a%10;//個位
n=(a%100-m)/10;//十位
p=a/1000;//千位
q=a%1000/100;//百位
x=pow(p,4);
y=pow(q,4);
z=pow(n,4);
s=pow(m,4);
if (x+y+z+s==a)
{
printf("%d%d%d%d\t",p,q,n,m);
}

}
void main()
{
int i;
for (i=1000;i<9999;i++)
{
abb(i);
}
}

運行結果:
1634 8208 9474

G. 用c語言編輯一個玫瑰花數(一個四位數,各個數字的4次方之和等於它本身,求出滿足條件的所有四位數)的

#include <stdio.h>
main()
{
// 從鍵盤上輸入一個四位數,判斷其是否為四葉玫瑰數
// (提示:四葉玫瑰數是指一個四位數,它的每個位上的數字的4次冪之和等於它本身)
int rose,one,two,three,four;
scanf("%d",&rose);//
four=rose/1000;
three=rose/100%10;
two=rose/10%10;
one=rose%10;
four=four*four*four*four;
three=three*three*three*three;
two=two*two*two*two;
one=one*one*one*one;
if((four+three+two+one)==rose)
printf("%d",rose);

}

H. c語言輸出所有得水仙花數,玫瑰花數和五角星數

水仙花數即三位的自冪數。所謂自冪數,就是指一個 n 位數 ( n≥3 ),其每位上的數字的 n 次冪之和等於本身。
所以水仙花數,首先是三位數,形式為abc,同時a,b,c的立方和值與原本數相同。
類似的還有
四位自冪數:四葉玫瑰數
五位自冪數:五角星數
六位自冪數:六合數
等等。

對於水仙花數的判斷,需要按照以下步驟:
1 提取該數的個位,十位,百位值。
2 計算三個數的立方和。
3 與原值比較,如相等則是。

要輸出所有水仙花數,需要:
1 對所有三位數,即100到999遍歷;
2 對每個數判斷是否為水仙花數,如是則退出。
當循環結束,所有的水仙花數就輸出成功了。
代碼如下:

int isNarcissistic(int n)
{
int a = n/100;
int b = n/10%10;
int c = n%10;
return a*a*a + b*b*b + c*c*c == n;
}

int main()
{
int i;
for(i = 100; i< 1000; i ++)
if(isNarcissistic(i)) printf("%d ",i);
}

I. 為什麼在網上下載的用c語言編寫的玫瑰花程序 我用vc++6.0運行的時候,提

這個是tc專有的
說明原始程序
是用tc編寫 編譯的
用vs 或者vc都無法運行

你如果要用這個程序 需要針對vc進行修改
或者改用TC2.0