Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Feel free to optimize or correct the code at the Facebook page, your name will be added to the code ;)
- //https://www.facebook.com/AminproPastebin
- //Revised code
- #include <stdio.h>
- int main()
- {
- int num;
- int rev_num = 0;
- int perm;
- int remainder;
- printf("Enter a 6-digit integer:");
- scanf("%d", &num);
- printf("\n");
- perm = num; //Store original number in a permanent variable
- if(num > 100000){
- if(num < 1000000) {
- //6 Digit check
- //reverse program start
- while(num > 0)
- {
- rev_num = rev_num*10 + num%10; //add zero to the last digit such 10 becomes 100
- //This way we can add the last digit, 100 + 3 = 103
- //The last digit is obtained by getting the remainder of the number such as
- printf("%d\n", rev_num); //reversed number stored in Rev_num
- num = num/10;
- }
- //reverse program end
- printf("The reversed is %d\n", rev_num);
- //digit seperator start
- printf("The reversed digit intergers are ");
- while(perm)
- {
- remainder = perm % 10;
- perm = perm / 10;
- printf("%d ", remainder);
- }
- //digit seperator end
- }
- else{
- printf("Sorry, only 6-digit integers are accepted.");
- }
- }
- else{
- printf("Sorry, only 6-digit integers are accepted.");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement