Q-01: Write a C/C++ program to reverse a given number.
    

Using - C


#include<stdio.h> void main() { int num, revNum=0, remainder; printf("Enter a Number : "); scanf("%d",&num); while(num!=0) { remainder = num % 10; revNum = revNum * 10 + remainder; num /= 10; } printf("Reversed Number: %d",revNum); }

OUTPUT

Enter a Number     : 352
Reversed Number : 253
        

Using - C++


#include<iostream> using namespace std; int main() { int num, revNum=0, remainder; cout<< "Enter a Number : "; cin>> num; while(num!=0) { remainder = num % 10; revNum = revNum * 10 + remainder; num /= 10; } cout<< "Reversed Number: "<< revNum; return 0; }

OUTPUT

Enter a Number     : 35297
Reversed Number : 79253