Write a C++ program to print the given number in reverse order. Use functions with return type and without return type for reversing the number.
Ex: given number is 2345 , output should be 5432

Implementation of the above problem:
#include<iostream.h>
#include<math.h>
void reverse(int n)
{
int a;
cout<<"\nReverse output without return type is =";
while(n!=0)
{
a=n%10;
cout<<a;
n=n/10;
}
}
int reverse1(int n)
{
int a,c=0,x,z,b[100],i=0;
while(n!=0)
{
b[i]=n%10;
i++;
x=i;
n=n/10;
}
int y=x-1;
for(i=0; i<=x-1;i++)
{
z=b[i]*pow(10,y);
c=c+z;
y--;
}
return c;
}
int main()
{
int n;
cout<<"\nEnter the number to be reversed \n";
cin>>n;
reverse(n);
cout<<"\nReverse output with return type is ="<<reverse1(n);
return 0;
}


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

2 comments:

  1. You’ve made various nice points there. I did specific search terms around the matter and found mainly individuals will believe your site flat print

    ReplyDelete