Multiprogramming Language Trainer
Wednesday, 9 November 2016
C Program to Reverse a Number
#include<stdio.h>
#include<conio.h>
main()
{
int
n, reverse=0, rem;
clrscr();
printf(
"Enter a number: "
);
scanf(
"%d"
, &n);
while
(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf(
"Reversed Number: %d"
,reverse);
getch();
}
Output:
Enter a number: 123 Reversed Number: 321
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment