Monday, December 22, 2014

C Program to Reverse a Number Non-recursively

Posted By: BackBenchers World - Monday, December 22, 2014

Share

& Comment

#include<stdio.h>
#include<conio.h>

int reverse(int n)                                //Function to reverse a number
             {
                       int rev=0;
                       int temp;
                       temp=n;
                     
                                   while(temp!=0)
                                   {
                                               rev=(rev*10)+(temp%10);
                                               temp=temp/10;
                                               reverse(temp/10);
                                   }
                        return rev;
             }

void main()
{
                       clrscr();                       //Clears previous output screen

            int n;
            printf("Enter a number: ");
            scanf("%d",&n);
            printf("\nThe reverse of the number is: %d",reverse(n));

                       getch();                        //Wait until you press any key

}

About BackBenchers World

Techism is an online Publication that complies Bizarre, Odd, Strange, Out of box facts about the stuff going around in the world which you may find hard to believe and understand. The Main Purpose of this site is to bring reality with a taste of entertainment

0 comments:

Post a Comment

Copyright © 2013 TechDotHunter™ is a registered trademark.

Designed by Templateism. Hosted on Blogger Platform.