Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

reverse number


We can reverse a number in c using loop and arithmetic operators. In this program, we are getting number as input from the user and reversing that number. Let’s see a simple c example to reverse a given number.

  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int n, reverse=0, rem;
  6. clrscr();
  7. printf(“Enter a number: “);
  8.   scanf(“%d”, &n);
  9.   while(n!=0)
  10.   {
  11.      rem=n%10;
  12.      reverse=reverse*10+rem;
  13.      n/=10;
  14.   }
  15.   printf(“Reversed Number: %d”,reverse);
  16. getch();
  17. }

Output:

Enter a number: 123
Reversed Number: 321

Comments

comments