Tuesday, 7 January 2014

C Program to Reverse a Number

C Program to Reverse a Number

C program to reverse a number is very simple and easy to write. In the below code, i will use some graphics library function to print a message on screen in color.

#include<stdio.h>
#include<conio.h>
void main()
{
int no,rev=0,r,a;
clrscr();
textcolor(10);
cprintf("\n enter the number = ");
scanf("%d",&no);
a=no;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
cprintf("\n\n reverse of %d is = %d", a, rev);
getch();
}


Output

C++ Program to Reverse Of A Number

No comments:

Post a Comment