Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to reverse a number in C

Booking.com | Official site | The best hotels, flights, car rentals & accommodations


69 views
asked Sep 10, 2014 by avibootz
edited Mar 5, 2015 by avibootz

1 Answer

0 votes
#include <stdio.h> 
 
int main(void)
{
   int n, reverse = 0;
 
   printf("Enter a number: ");
   scanf("%d",&n); // 1234
 
   while (n != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + n % 10;
      n = n / 10;
   }
 
   printf("The reverse number is = %d\n", reverse); // 4321

   return 0;
}




answered Sep 10, 2014 by avibootz
edited Sep 10, 2014 by avibootz

Related questions

1 answer 21 views
21 views asked Dec 12, 2023 by avibootz
1 answer 54 views
54 views asked Aug 10, 2021 by avibootz
1 answer 51 views
51 views asked Jul 26, 2021 by avibootz
1 answer 65 views
1 answer 101 views
...