/* This program takes a five-digit
integer from user, and shows its reverse.*/
#include<stdio.h>
#include<conio.h>
int main ()
{
/*Declaring and initializing
variables*/
int value,dig1,dig2,dig3,dig4,dig5,reverse,temp;
/*prompt to take the input*/
printf("Please enter a five-digit number: ");
/*Taking input*/
scanf("%d",&value);
temp = value
;
/*Calculations*/
dig1 =
value % 10;
/* e.g. if value is 12345 then 12345 % 10 gives 5*/
value =
value / 10;
/* '12345/10' gives '1234.5' but this is integer division
so digit/s after '.' will
be dropped and we get '1234'*/
dig2 =
value % 10;
/*now '1234 % 10' gives '4' and so on*/
value =
value / 10;
dig3 =
value % 10;
value =
value / 10;
dig4 =
value % 10;
value =
value / 10;
dig5 =
value % 10;
reverse =
(dig1*10000) + (dig2*1000) + (dig3*100) + (dig4*10) + (dig5) ;
/*showing Results*/
printf("\n
Solution: ");
printf("\n
__________");
printf("\n\n By
reversing %d it becomes : %d",temp,reverse);
getch();
return 0;
}
Kanhaiya Kumar Singh
ReplyDeletedo u get output for this program
This comment has been removed by the author.
ReplyDelete
ReplyDeleteint main()
{
int a,b,c,d,e,f;
printf("\n\nenter Five Digit number= ");
scanf("%d",&a);
f=a%10;
a=a/10;
b=a%10;
a=a/10;
c=a%10;
a=a/10;
d=a%10;
a=a/10;
e=a%10;
a=a/10;
printf("\n\n\nreverse of five digit number= %d%d%d%d%d\n\n\n\n",f,b,c,d,e);
getch();
return 0;
}
enter five digit number=
Delete24624
4
4
4
4
4
sir why we *digit1 with 10000,1000,100,10,5
ReplyDeleteThis is helpful and specially thanks for writing comments
ReplyDeleteI have method which is better than all others
ReplyDelete