Pages

Tuesday, 25 December 2012

PROPERTIES OF A NUMBER


/* Properties Of A Number */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
 {
  int n,c,sum=0,r,rev,flag=0,chk,i;
  printf("\n Enter the Number      :  ");
  scanf("%d",&n);
  chk=n;
 while(7)
 {
   printf("\n\n 1 Palindrome or Not\n 2 Amstrong or Not\n 3 Prime or Not  \n 4 Strange or Not \n 5 Perfect or Not \n 6 Exit  ");
   printf("\n\nEnter the choice  :  ");
   scanf("%d",&c);
   switch(c)
    {
     case 1:chk=n;
            rev=0;
            while(n>0)
             {
              r=n%10;
              rev=rev*10+r;
              n=n/10;
             }
            if(rev==chk)
             printf("\n\t Number is palindrome ");
            else
             printf("\n\t Number is not palindrome ");
             break;
    case 2:n=chk;
           rev=0;
           while(n!=0)
            {
             r=n%10;
             sum+=(r*r*r);
             n=n/10;
            }
             if(sum==chk)
             printf("\n\t Number is Amstrong");
            else
             printf("\n\t Number is not Amstrong");
             break;
     case 3:i=2;
            while(i<=n/2)
             {
              if(n%i==0)
               {
                flag=1;
                break;
                   }
              i++;
             }
            if(flag==1)
             printf("\n\t Number is not prime");
            else
             printf("\n\t Number is prime");
            break;
     case 4:n=chk;
            sum=0;
            i=0;
            while(n>0)
              {
               n=n/10;
               i++;
              }
            n=chk;
           while(n>0)
            {
             r=n%10;
             sum+=pow(r,i);
             n=n/10;
            }
             if(sum==chk)
             printf("\n\t Number is Strange");
            else
             printf("\n\t Number is not Strange ");
            break;
    case 5:n=chk;
           sum=0;
           for(i=0;i<=n/2;i++)
            {
             r=n%i;
             if(r==0)
              {
               sum+=i;
              }
             }
            if(sum==chk)
              printf("\n\t Number is perfect");
            else
              printf("\n\t Number is not perfect");
            break;
    case 6:exit(0);
    default:printf("Error in choice");
           break;
  }
 }
}


No comments:

Post a Comment