求这样一个三位数,该三位数等于其每位数字的阶乘之和

时间:2020-12-24 00:10:51
#include<stdio.h>

int main()
{
	int a,b,c,n;
	int fun(int i);
	
	for(n = 100;n < 1000;n++){
	
		a = n / 100;
		b = (n / 10) % 10;
		c = n % 10;

		if(n == (fun(a) + fun(b) + fun (c))){
		printf("%d=%d!+%d!+%d!\n",n,a,b,c);
		}
	}
}
	
int fun(int i)
{
	int s = 1;
	int l = 1;
	
	while(s <= i){
	l *= s;
	s++;
	}
	return l;
}