Function call + Enumeration method
/*
==========================================================
Title: Ask for a three-digit positive integer = The sum of the factorial of the numbers of its members!
such as: 145=1!+4!+5!.
==========================================================
*/
#include <stdio.h>
int J (int n)
{
int t=1,i;
for (i=1;i<=n;i++)
T*=i;
return (t);
}
Main ()
{
int S,i,ge,shi,bai,qian;
for (s=100;s<1000;s++)
{
ge=s%10;
shi=s/10%10;
bai=s/100%10;
if (S==j (GE) +j (shi) +j (bai))
printf ("%d=%d!+%d!+%d!\n", S,bai,shi,ge);
}
}
/*
==========================================================
Comment: First write a function J for factorial, and then use division and remainder to find out "a 1000"
Bit, the number that matches the IF condition is found through the enumeration method.
==========================================================
*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C language Function call 02-A positive integer of three digits = the sum of the factorial of the numbers of its members