Here is the program to mathematically reverse the entered integer. The program uses simple library functions, and an easy flow.
Logic : The main idea here is to trace the entered number till its length, and slicing up in each of the iterations. The program asks the user to enter the number to reverse. Sets two variable flags to hold each digits and the final reversed number.
The while loop slices down the given number to digits, and appends to the reversed flag ‘rev’. Finally it prints out the reversed number after exiting from the while loop.
The similar logic for slicing up the given number is used in other programs like, finding the sum of digits and, palindrome checking programs
#include<stdio.h>
#include<math.h>
void main()
{
long int num, rev = 0, dig;
clrscr();
printf(“nnt ENTER A NUMBER…: “);
scanf(“%ld”, &num);
while(num>0)
{
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
printf(“nt REVERSED NUMBER IS…: %ld”, rev);
getch();
}
Download exe and source code here.
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
October 24th, 2010 at 12:57 pm
Hello, You clearly are someone who recognizes the electrical power of focus and how to make plans which you achieve action by phase.Bravo for you.In my personal lifestyle We’ve only witnessed accomplishment when I have kept my emphasis and built the steps wanted to realize my plans – extremely small happens by transform alone. This really is one thing I prefer to repeatedly share with my readers.Truly, I am delighted to go through about other peoples good results through laser like target and you’ve got it.Continued good results for you,David
March 23rd, 2011 at 3:51 pm
sir ur program was very helpful..thanx….