adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to print reverse of a given number in different ways (100 rev 001)

Program in C to print reverse of given number in different ways


For example :
      num = 100
      rev  =  001

1st way

// Programming.OM
#include<stdio.h>
  int main()
    {
     int n,r;
     printf("Enter a number:-");
     scanf("%d",&n);printf("Reverse = ");
     while(n>0)
      {
        r=n%10;
        printf("%d",r);
        n/=10;
      }
   return 0;
 }



Output:-








2nd way

// Programming.OM
#include<stdio.h>
  int main()
    {
     int i,n,r;
     char rev[10];
     printf("Enter a number:-");
     scanf("%d",&n);
     i=0;
     while(n>0)
      {
        r=n%10;
        rev[i++]=48+r;
        n/=10;
      }
     rev[i]='\0';
     printf("Reverse = %s",rev);
   return 0;
 }


Output:-




Post a Comment

2 Comments

subham kumar said…
Nice program . visit more good coding program collection Click Here