8.29.2011

operation's number(sum,reverse,store in other variable)

Q. Write a program to insert a number and do following tasks:
 a.Display in reverse order?
 b.Reverse in another variable and display it?
 c.Display sum of its all digit?

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
 int x,num,rem,sum=0,var=0;
 clrscr();
 printf("\nPress Number 1 for reverse number");
 printf("\nPress Number 2 for reverse number in another variable");
 printf("\nPress Number 3 for sum of entered number");
 scanf("%d",&x);
 switch(x)
 {
 case 1 :
  printf("\nEnter Number : ");
  scanf("%d",&num);
  while(num>=1)
  {
   rem=num%10;
   printf("Reverse number : %d",rem);
   num=num/10;
  }
  break;
 case 2 :
  printf("Enter Number : ");
  scanf("%d",&num);
  while(n>=1)
  {
   rem=n%10;
   var=var*10+rem;
   n=n/10;
  }
  printf("%d",var);
  break;
 case 3 :
  printf("\nEnter Number : ");
  scanf("%d",&num);
  while(num>=1)
  {
   rem=num%10;
   sum=sum+rem;
   num=num/10;
  }
  printf("Sum of %d is %d",num,sum);
  break;
 default :
   printf("You enter wrong number!!!");
   break;
 }
}

       Output of above program : 

Press Number 1 for reverse number
Press Number 2 for reverse number in another variable
Press Number 3 for sum of entered number

1
Enter Number : 4812
Reverse number : 2184
 

No comments:

Post a Comment