If a five digit number is input through the keyboard, write a program to reverse the number.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int num, p;
long revnum = 0;
clrscr ( );
printf ("\n\n\n\t Enter a five digit number (less than 32767)...:"); scanf ("%d",&num);
p = num % 10; /* last digit extracted as reminder */
num = num /10; /* remaining digits */
revnum = revnum + p * 10000L; /* revnum updated with value of extracted digit */
p = num % 10; /* fourth digit */
num = num /10; /* remaining digits */
revnum = revnum + p * 1000;
p = num % 10; /* third digit */
num = num /10; /* remaining digits */
revnum = revnum + p * 100;
p = num % 10; /* second digit */
num = num /10; /* remaining digits */
revnum = revnum + p * 10;
p = num % 10; /* first digit */
revnum = revnum + p;
printf ("\n\n\n\t The reversed number is...:%ld", revnum);
getch ( );
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
void main ( )
{
int num, p;
long revnum = 0;
clrscr ( );
printf ("\n\n\n\t Enter a five digit number (less than 32767)...:"); scanf ("%d",&num);
p = num % 10; /* last digit extracted as reminder */
num = num /10; /* remaining digits */
revnum = revnum + p * 10000L; /* revnum updated with value of extracted digit */
p = num % 10; /* fourth digit */
num = num /10; /* remaining digits */
revnum = revnum + p * 1000;
p = num % 10; /* third digit */
num = num /10; /* remaining digits */
revnum = revnum + p * 100;
p = num % 10; /* second digit */
num = num /10; /* remaining digits */
revnum = revnum + p * 10;
p = num % 10; /* first digit */
revnum = revnum + p;
printf ("\n\n\n\t The reversed number is...:%ld", revnum);
getch ( );
}
Click here to contact us
No comments:
Post a Comment