Wednesday

Write a C program to read a four digit number and display it in reverse order.

#include<stdio.h>
#include<conio.h>
void main()
  {
    int c=0,n,r,s=0;
    clrscr();
    printf("\n Enter any 4 digit number: ");
    scanf("%d",&n);
    while(n!=0)
    {
     r=n%10;
     s=s*10+r;
     n=n/10;
     c=c+1;
    }
    if(c<=4)
    printf("\n Reversed number is %d",s);
    else
    printf("\n It is not a 4 digit number");
  getch();
  }

No comments:

Post a Comment

Rahul-Notes