Code Box
---------------------------------------------
/*Program to find reverse of a number by do while loop in C*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,num1,rem,newnum;
clrscr();
newnum=0;
printf("\n\tReverse Number maker");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);
num1=num; //to save actual number
printf("\nBy Method 1:");
while(num1>=1)
{
rem=num1%10;
num1=num1/10;
newnum=newnum*10+rem;
}
printf("\nReverse of number is : %d",newnum);
printf("\n-------------------------");
printf("\nBy Method 2:");
while(num1!=0)
{
rem=num1%10;
num1=num1/10;
newnum=newnum*10+rem; //formula to reverse
}
printf("\nReverse of number is : %d",newnum);
getch();
}
No comments:
Post a Comment