首页
/
每日頭條
/
科技
/
sinx編程教程
sinx編程教程
更新时间:2025-10-28 04:31:57

sinx編程教程(水仙花數燒腦編程)1

//水仙花數是指一個N位數(N>3),他的每個位上的數字的N次幂之和等于他本身,例如

//153=1*1*1 5*5*5 3*3*3 本題默認 N=3(比較簡單)

#include<stdio.h> //預處理命令

int main () //主函數

{

int i,a,b,c; //定義整型 i,a,b,c

for (i=100;i<1000;i ) //執行循環語句 i 的初始值為100;當i<1000的時候執行以下循環;

//每一次循環結束後i自身 1 (這個循環的作用是從100到999符合條件的輸出來!

{

a=i/100; //a是一個整型值比如121/100=1.21但是a=1省略小數部分,下同.

b=(i-a*100)/10;

c=i-(a*100)-(10*b);

if(a*a*a b*b*b c*c*c==i)printf("%d\n",i); //輸出符合條件的i的值

}

return 0;

}

//以後的代表解析,如有不懂,請私聊!

如要N>3的完整過程,點個贊關注一下,私聊給我!

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2025 - www.tftnews.com All Rights Reserved