C C++ program to find reverse of digits of given number

 

Flowchart

Reverse of digits given number flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,rem,rev=0;
printf(“Enter a number: “);
scanf(“%d”,&num);
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
printf(“Reverse of digits = %d”,rev);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,rem,rev=0;
cout<<“Enter a number: “;
cin>>num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
cout<<“Reverse of digits = “<<rev;
return 0;
}

 

Output

Reverse of digits given number output

 

Published by

admin

I am a computer teacher, programmer and web developer