Introduction

The main purpose of this blog is to share our experience with the world and get experience from the world. This will be a new venture for us and we are sure, we shall learn a lot with it. we will try to Explore our mind which will be very helpful for all us. As from its name, its a blog covering all the topics. we will try to post all the interesting topics and give our opinion. Do give your point of view in comments.


"NAVIGATE VIA BLOG ARCHIVE ON RIGHT TO GET WHAT YOU ARE LOOKING FOR"


Wednesday, January 26, 2011

C CODE TO REVERSE 5 DIGIT NUMBER

/*this program will reverse the five digit number*/
#include<stdio.h>
int main()
{
int no,b,c,d,e,rev; /*no is the number entered by user rev is the reverse number which will be displayed at the end*/
printf("enter a five digit no.\n");
scanf("%d",&no);
if(no<=99999 && no>=10000)        /*this if statement is to make sure that user enters a five digit number
                                    otherwise the program will display "you have not entered a five digit number"*/
{
  b=no/10;      /*int  is used so number after decimal will be neglected*/
  c=b/10;
  d=c/10;
  e=d/10;
  rev=(no-10*b)*10000;      /*this formula will calculate unit digit of number entered by user and multiply by 10000
                              in this way it will become first digit of reverse number*/  
  rev=rev+((b-10*c)*1000); /*this formula will calculate the tens digit of number entered by user and multiply by 1000
                             the resultant will be added to previous calculated no. i.e rev so first two digits are
                             reversed.in the similar way all digits will be reversed*/
  rev=rev+((c-10*d)*100);
  rev=rev+((d-10*e)*10);
  rev=rev+e;
  printf("%d\n",rev);
}
else          /*this else is with the first if statement*/
printf("you have not entered a five digit no.\n");
return 0;
}

No comments:

Post a Comment

Related Posts with Thumbnails