#include<stdio.h>intsxh(intnumber);//sxh=水仙花數intmain(){inti;printf("輸出一個三位數:");scanf("%d",&i);if(sxh(i))printf("thedata%5disyes\n",i);printf("\n");return0;}intsxh(intnumber) //定義判斷水仙花數的函式{intsum=0,item,count=1,i=1,temp;temp=number; while(temp>=10) {count++; //判斷位數temp/=10; } temp=number; while(i<=count) { item=temp%10;temp/=10;sum=sum+item*item*item;i++; } if(sum==number) return1; else return0;}
#include<stdio.h>intsxh(intnumber);//sxh=水仙花數intmain(){inti;printf("輸出一個三位數:");scanf("%d",&i);if(sxh(i))printf("thedata%5disyes\n",i);printf("\n");return0;}intsxh(intnumber) //定義判斷水仙花數的函式{intsum=0,item,count=1,i=1,temp;temp=number; while(temp>=10) {count++; //判斷位數temp/=10; } temp=number; while(i<=count) { item=temp%10;temp/=10;sum=sum+item*item*item;i++; } if(sum==number) return1; else return0;}