Sathvikks8

Lab Program 3

Apr 10th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. //Program 3
  2. #include<stdio.h>
  3. #include<math.h>
  4. void main()
  5. {
  6.     int orig_number,rev_number,last_digit,a;
  7.     rev_number=0;
  8.     goto input;
  9.     input:
  10.     {
  11.     printf("Enter the number ");
  12.     scanf("%d",&orig_number);
  13.     }
  14.     if(orig_number<=0)
  15.     {
  16.         printf("\nZero and negative numbers cannot be taken as input. Try again\n\n");
  17.         goto input;
  18.     }
  19.     a=orig_number; //creating a duplicate of the original number
  20.     while(a>0)
  21.     {
  22.         last_digit=a%10;
  23.         rev_number=rev_number*10+last_digit;
  24.         a=a/10;
  25.     }
  26.     printf("\nThe reversed number is %d",rev_number);
  27.     if(rev_number==orig_number)
  28.         printf("\nThe entered number is a palindrome");
  29.     else
  30.         printf("\nThe entered number is not palindrome");
  31.    
  32. }
Add Comment
Please, Sign In to add comment