C语言求水仙花数

阅读 44

2022-04-19

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void check_count();
void combineNum(int x, int y, int z,int num);
void printDiamond(int x, int y);
void purchaseChicken();
float calculatePi();
void primeJudge();
void perfectJudge();
void intimacyNumber();
void automorphic();
void narcissisticNumber();
int main() {
	narcissisticNumber();
	return 0;
}


//水仙花数
void narcissisticNumber() {
	int num = 100;
	int onesPlace = 0, tensPlace = 0, hundredsPlace = 0;
	while (num<1000) {
		onesPlace = num % 10;
		tensPlace = (num%(int)1e2)/10;
		hundredsPlace = num / (int)1e2;

		if (num==(pow(onesPlace,3)+pow(tensPlace,3)+pow(hundredsPlace,3))) {
			printf("%d=%d^3+%d^3+%d^3\n",num,onesPlace,tensPlace,hundredsPlace);
		}
		num++;
	}
}

精彩评论(0)

0 0 举报