Logic:
- Enter the number n example n=345
- Reverse=543
Algorithm
- Enter the number as n
- Initially assign rev=0
- while(n>0)
- {
- r=n%10;
- rev = rev * 10 + r;
- n=n/10;
- }
- Print rev
Program
#include<stdio.h> int main() { printf("***************************************************************"); printf("\n***************************************************************"); printf("\n** WAP to find reverse of a number *"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n***************************************************************"); printf("\n***************************************************************\n"); int i,n,r,rev=0; printf("Enter the no n \n"); scanf("%d",&n); while(n>0) { r=n%10; n=n/10; rev=rev*10+r; } printf("reverse is %d",rev); }
Output 1
*************************************************************************** *************************************************************************** ** WAP to find reverse of a number * ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** *************************************************************************** *************************************************************************** Enter the no n 456 reverse is 654