當前位置:首頁 » 玫丹百香 » 玫瑰花數程序

玫瑰花數程序

發布時間: 2022-06-29 03:15:04

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

#include<stdio.h>
intmain()
{
inti,j,t;
for(i=1000;i<10000;i++)
{
t=0;
for(j=i;j;j/=10)
t+=(j%10)*(j%10)*(j%10)*(j%10);
if(t==i)
printf("%d ",i);
}
}


Output:
1634
8208
9474

Ⅱ c語言中什麼是玫瑰花數

# include <iostream.h>
# include <math.h>
# define SIZE 10
int main()
{
long i,j;
long a[SIZE];
long temp;
long count=0;
long sum=0;
cout<<"玫瑰花數:"<<endl;
for(i=(long)(pow(10,4-1));i<(long)pow(10,4);i++)
{
temp=i;
while(temp!=0)
{
a[count++]=temp%10;
temp/=10;
}
for(j=0;j<count;j++)
{
sum+=(long)(pow(a[j],4));
}
if(sum==i)
{
while(count>1)
{
cout<<a[--count]<<"^"<<4<<"+";
}
cout<<a[--count]<<"^"<<4<<"="<<sum<<endl;
}
sum=0;
count=0;
}
return 0;
}
可以了哈,試試嘛

Ⅲ C語言:一行一個,在屏幕上輸出所有四葉玫瑰數,用while循環,咋編

按照你的要求編寫的輸出所有四葉玫瑰數的C語言程序如下

Ⅳ 四葉玫瑰數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;
}

Ⅳ 用pascal編寫程序 如果一個4位數等於它的每一位數字4次方之和,則稱為玫瑰花數,求所有的玫瑰花數。

程序:

var

i,k,x:longint;

begin

for i:=1000 to 9999 do//枚舉所有的四位數,因為玫瑰花數一定是四位數

begin

k:=0;

x:=i;

while x>0 do

begin

k:=k+sqr(sqr(x mod 10));//這里可能太快了。這樣子,設n表示目前x的各位,則n的四次方為n*n*n*n,而sqr為求平方數,所以sqr(sqr(n))=sqr(n*n)=n*n*n*m。將結果累加到k上比較

x:=x div 10;//截去當前的個位

end;//以上為求該數每一位數字4次方之和,掃描就是從個位到千位的順序

if k=i then writeln(i);//相等就輸出

end;

end.

輸出應該是這樣,不懂再追問

Ⅵ 四葉玫瑰數的VB怎麼編

四位數各位上的數字的四次方之和等於本身為四葉玫瑰數。回

實現源碼答如下:
program roseNumber;
var
a,b,c,d:longint;

function four(n:longint):longint;
begin
four:=n*n*n*n;
end;

begin
for a:=1 to 9 do
for b:=0 to 9 do
for c:=0 to 9 do
for d:=0 to 9 do
begin
if(1000*a+100*b+10*c+d=four(a)+four(b)+four(c)+four(d))then
begin
writeln(a,b,c,d);
end
end
end.

Ⅶ 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++程序 玫瑰花數

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

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

輸出是 1634 8208 9474

#include<stdio.h>

int rose(int digit) {

int n = digit;
int k=0;
int value = 0;
int sum = 0;

while(n>0) {
k = n % 10;
sum += k*k*k*k;

n /= 10;
}

if( sum == digit) {
return 1;
}
return 0;
}

int main()
{
int i;
int count = 0;
for(i=1000; i<=9999; i++) {
if (rose(i)) {
count++;
printf("%4d ", i);
}
}

getchar();
return 0;
}

Ⅹ 編程題(玫瑰花數)

//java程序
for(inti=1000;i<10000;i++){
inta=i/1000;
intb=(i-a*1000)/100;
intc=(i-a*1000-b*100)/10;
intd=i-i/10*10;
if(i==Math.pow(a,4)+Math.pow(b,4)+Math.pow(c,4)
+Math.pow(d,4)){

System.out.println(""+a+b+c+d);
}
}

希望能幫上其他小夥伴

熱點內容
深根花卉 發布:2025-10-20 08:51:57 瀏覽:737
詩意花藝 發布:2025-10-20 08:43:24 瀏覽:824
樹枝橡皮泥插花 發布:2025-10-20 08:42:21 瀏覽:445
海棠獎章 發布:2025-10-20 08:42:19 瀏覽:99
國畫蘭花教程 發布:2025-10-20 08:37:19 瀏覽:830
用手工紙做玫瑰花 發布:2025-10-20 08:25:41 瀏覽:964
夢見野百合花 發布:2025-10-20 08:04:13 瀏覽:546
土豆蘿卜西蘭花歌詞 發布:2025-10-20 08:01:16 瀏覽:577
剪紙2荷花 發布:2025-10-20 08:00:34 瀏覽:285
紅盒荷花煙 發布:2025-10-20 08:00:29 瀏覽:893