1. 用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);
}
2. 輸出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);
}
方法比較笨,但更容易理解。望樓主採納。。。
3. 四葉玫瑰數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;
}
4. 為什麼在網上下載的用c語言編寫的玫瑰花程序 我用vc++6.0運行的時候,提
這個是tc專有的
說明原始程序
是用tc編寫 編譯的
用vs 或者vc都無法運行
你如果要用這個程序 需要針對vc進行修改
或者改用TC2.0
5. c語言中什麼是玫瑰花數
c語言中的玫瑰花數是指一個四位數等於它的各數位上的數字的四次方和。
c語言介紹;C語言是一門通用計算機編程語言,應用廣泛,C語言的設計目標是提供一種能以簡易的方式編譯,產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。
6. C語言:一行一個,在屏幕上輸出所有四葉玫瑰數,用while循環,咋編
按照你的要求編寫的輸出所有四葉玫瑰數的C語言程序如下
7. 為什麼在網上下載的用c語言編寫的玫瑰花程序 我用vc++6.0運行的時候,提示找不到這個<graphics.h>文件!
vc裡面是沒有這個庫文件的,從網上下一個把
8. 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;
}