fork(1) download
  1. #include <stdio.h>
  2. int fact(int);
  3.  
  4. int main(void) {
  5. int n,rem,sum=0,h;
  6. printf("enter the number\n");
  7. scanf("%d",&n);
  8. h=n;
  9. while(n!=0)
  10. {
  11. rem=n%10;
  12. sum=sum+fact(rem);
  13. n=n/10;
  14. }
  15. if(h==sum)
  16. printf("%d is a peterson number",h);
  17. else
  18. printf("%d is not a peterson number",h);
  19. return 0;
  20. }
  21. int fact(int num)
  22.  
  23. {
  24. int f=1,i;
  25. for(i=1;i<=num;i++)
  26. {
  27. f=f*i;
  28. }
  29. return f;
  30.  
  31. }
  32.  
Success #stdin #stdout 0s 9424KB
stdin
145
stdout
enter the number
145 is a peterson number