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;
  }
 }
}

CALCULATOR USING SWITCH CASE



/* Calculator using Switch Case */
#include<stdio.h>
#include<stdlib.h>
void main()
 {
  int a,b,c;
  float s;
  printf("\nEnter two numbers:");
  scanf("%d%d",&a,&b);
  printf(" 1.Addition  \n 2.Subtraction \n  3.multiplication \n  4.Division  \n  5.Exit \n");
  printf("\nEnter the choice:");
  scanf("%d",&c);

     switch(c)
      {
        case 1:printf("The sum is %d",a+b);
                break;
        case 2:printf("The Subtraction is %d",a-b);
                break;
        case 3:printf("The multiplication is %d",a*b);
                break;
        case 4:s=a/b;
                printf("The Division is %f",s);
                break;
        case 5:exit(0);
        default:printf("Invalid Option");
                break;
      }
 }


FACTORIAL OF A NUMBER



/* Factorial Of A Number */
#include<stdio.h>
void main()
 {
  int n,f=1,i=1;
  printf("Enter the number:\n");
  scanf("%d",&n);
    while(i<=n)
     {
      f=f*i;
      i++;
     }
  printf("Factorial of the number is %d",f);
}


REVERSE OF A NUMBER



/* Reverse Of A Number */
#include<stdio.h>
#include<math.h>
void main()
 {
  int n,rev=0,sum=0,r;
  printf("Enter the number");
  scanf("%d",&n);
  while(n!=0)
   {
    r=n%10;
    rev=(rev*10)+r;
    sum=r+sum;
    n=n/10;
   }
  printf("Reverse is %d ",rev);
  printf("Sum of digit is %d",sum);
}




TEMPERATURE CONVERSION


/* Temperature Conversion */
#include<stdio.h>
void main()
 {
  int t,k;
  float f;
  printf("Enter the temperature which you want to covert:\n");
  scanf("%d",&t);
  k=t+273;
  f=(t+32)*5/9;
  printf("The fareheit scale is %f and kelvin scale is %d",f,k);
 }



SIMPLE CALCULATOR



/* simple calculator */
#include<stdio.h>
#include<string.h>
void main()
 {
  int a,b;
  printf("Enter two Numbers:");
  scanf("%d%d",&a,&b);
 /* printf("Enter the operation you need:\n");
  scanf("%c",op);*/


    printf("The sum is %d\n",a+b);

    printf("The Difference is %d\n",a-b);

    printf("The Division is %d\n",a/b);

    printf("The Multiplication is %d\n",a*b);

 }