Write a C-program to obtain the reversed number

 

TASK 3-

A five-digit number is entered through the keyboard. Write a C-program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.

CODE:

#include<stdio.h>
int digit(int x);

int main(){
     int x,r;
    printf("Enter the number: ");
    scanf("%d",&x);
    r=digit(x);
    if (r==x)
    printf("\nreverse of the number is same as original");
    else
     printf("\nreverse of the number is not same as original");
getchar();
return 0;

}

int digit(int x)
{
     static int d,sum=0;
     if (x>0)
     {
              d=x%10;
              sum=(sum*10)+d;
              x/=10;
              digit(x);
     }
     return sum;

}

OUTPUT:


NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

Post a Comment (0)
Previous Post Next Post