We provide Engineering,HSEB notes, tutorials which can be helpful for students during college life.
Wednesday, April 8, 2015
28. Write a program to read a four digit number and display it in reverse order.
#include <stdio.h>
#include <conio.h>
void main()
{
int num,rev=0,rem;
clrscr();
printf("\n Input a 4 digit numberz- ");
scanf("%d",&num);
do
{
rem=num%l0;
rev=rev*l0+rem;
num=num/10;
}while(num>0);
printf("\n Reverse number = %d",rev);
getch();
}
Alternate method
#include <stdio.h>
#include <conio.h>
void main()
{
int num,first,second,third,fourth,rev;
clrscr(); _
printf("\n Input a 4 digit numberz- ");
scanf(“%d",&num);
first = num%10;
num = num/10;
second = num%l0;
num = num/10;
third= num%l0;
num = num/10;
fourth = num%l0;
num=num/10;
rev=first*1000+second*100+third*10+fourth*1;
printf("\n Reverse number =%d", rev);
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment