Friday 3 June 2016

Write a program that prompts the user to enter a number and reverse it. Write a function Reverse() to reverse the number. The function should accept the number as the parameter and return the reverse number.

#include<iostream.h>
#include<conio.h>
int Reverse(int num);
void main()
{
        clrscr();
        int n, r;
        cout<<"Enter a number: ";
        cin>>n;
        r = Reverse(n);
        cout<<"The reverse number is : "<<r;
        getch();
}

int Reverse(int num)
{
        int rev_num = 0;
        while(num > 0)
        {
                rev_num = rev_num * 10 + num % 10;
                num = num / 10;
        }
        return rev_num;
}
Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20