Search This Blog

Translate

write a c program to check number is r even or odd,Armstrong no,prime no using switch case


write a c program to check number is r even or odd,Armstrong no,prime no using switch case


#include
#include
void main()
{
  int ch,a,b=0,c,i,rem,flag=1,sum=0;
  clrscr();
  printf("\n Enter the number:");
  scanf("%d",&a);
      c=a;
  while(1)
  {
    printf("\n---------------------Menu-----------------------\n");
    printf("\n 1.Find even/odd \n 2.Find prime \n 3.Armstrong no \n 4.exit");
    printf("\n-------------------------------------------------\n");
    printf("Enter your choice:");
    scanf("%d",&ch);
    switch(ch)
    {
      case 1:if(a%2==0)
          printf("\n Number is even");
        else
         printf("\n Number is odd");
          break;
      case 2: for(i=2;i          {
           if(c%i==0)
           {
        flag=0;
        break;
           }
          }
           if(flag==1)
        printf("\n Not prime");
           else
        printf("\n Prime");
         break;
      case 3:
           while(c>0)
           {
        rem=c%10;
        b=rem*rem*rem;
        sum=sum+b;
        c=c/10;
          }
          if(a==sum)
           printf("\n No is armstrong ");
          else
        printf("\n No is not armstrong "); break;

    case 4:exit(0);
    default:printf("\n Enter choice between 1 to 4 only");
    }
  }
 getch();
}

C Program example List

Google+ Badge