Saturday, June 4, 2011

C Program to check whether a number is a Peterson Number or not

#include<stdio.h>
#include<conio.h>
void main()
{
         int n,c,s=0,m,i,f=1;
         clrscr();
         printf("\n ENTER A VALUE : ");
         scanf("%d",&n);
         m=n;
         while(n>o)
         {
              c=n%10;
              for(i=0;i<c;i++)
                   f=f*i;
              s=s+f;
              f=1;
              n=n/10;
         }
         if(s==m)
              printf("\n THE ENTERED NUMBER IS PETERSON
NUMBER.");
          else
              printf("\n THE ENTERED NUMBER IS NOT A
PETERSON NUMBER.");
          getch();
}

1 comment:

  1. i think the initialization in for loop is wrong. f will always be zero. right thin is for(i=1;i<=n;i++)

    ReplyDelete