answersLogoWhite

0


Best Answer

Program to reverse ANY given number in C

#include

main()

{

int num,mod,rev=0;

printf("Enter a number:");

scanf("%d", &num);

while(num>0)

{

mod=num%10;

rev=(rev*10)+mod;

num=num/10;

}

printf("Reverse of the given number: %d", rev);

getchar();

}

Other Ideas! Use the While Loop

#include

main()

{

int a,b,c,d,e;

printf("Enter the Number to Find it's Reverse\n");

scanf("%d",&a);

while(a!=0)

{

b=a%10;

c=a/10;

printf("%d",b);

a=c;

}

getchar();

}

Before compiling include stdio.h

-----------------------------------------------------------------------------

Using sprintf/atoi functions./..

int _tmain(int argc, _TCHAR* argv[])

{

int inumber;

printf("\n\n Enter a Number:");

scanf("%d",&inumber);

char pNumber[10];

sprintf(pNumber, "%d", inumber);

int iLength=strlen(pNumber);

char temp;

for(int i=0;i

temp=pNumber[i];

pNumber[i]=pNumber[iLength-1];

pNumber[iLength-1]=temp;

iLength--;

}

inumber=atoi(pNumber);

printf("\n\nReverse no is %d",inumber);

getchar();

return 0;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int abcd;

printf("enter a 4-digit no.");

scanf("%d",&abcd);

a=abcd/1000;

abcd=abcd%1000;

b=abcd/100;

abcd=abcd%100;

c=abcd/1o;

abcd=abcd%10;

d=abcd;

printf("reverse=%d",dcba);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

h = x/100; // (1) x = 325, h = 3 (2) x = 1, h = 0

u = x%10; // (1) u = 5 (2) u = 1

y = x - 99* (h - u); // (1) y = 325 - (-198) = 523 (2) y = 1 - (-99) = 100

OK? Comments show two examples, 325 to 523 and 1 to 100.

h=num%100 u=h%10

g=num/100

i=h/10

numreverse=u*100+i*10+g

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b;

printf("Enter number:\t);

scanf("%d",a);

printf("Reversal of number: ");

do {

b=a%10;

printf("%d",b);

a = a/10;

} while(a>0);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

16y ago

//Reverse of the Number

// Programme Written By Maulin Thaker Ahmedabad;

#include

#include

void main()

{

int a,b,c,d,e;

clrscr();

printf("Enter the Number to Find it's Reverse\n");

scanf("%d",&a);

while(a!=0)

{

b=a%10;

c=a/10;

printf("%d",b);

a=c;

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int n,a,b;

long int revnum=0;

clrscr();

printf("\n Enter three digit number");

scanf("%d", &n);

a=n%10;

n=n/10;

revnum=revnum+a*100;

a=n%10;

n=n/10;

revnum=revnum+a*10;

a=n%10;

revnum=revnum+a;

printf("\nThe reversed number is %ld",revnum);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<srdio.h>

#include<conio.h>

void main()

{

int num,reverse;

clrscr();

printf("enter any number ==>")

scanf("%d",&num);

reverse=rev(num);

printf("reverse of number is==>%d",reverse);

getch();

}

int rev(int num)

{

static sum,r;

if(num)

{

r=num%10;

sum=sum*10+r;

rev(num%10);

}

else

return 0;

return sum;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include<stdio.h>

#include<conio.h>

int main (void)

{

int n,s=0,d;

clrscr();

printf("\n Enter the no. which u want to reverse\n");

scanf("%d",&n);

while(n>0)

{

d=n%10;

s=s*10+d;

n=n/10;

}

printf("\nThe reverse no. is=%d",s);

getch();

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

int RevNum( int num )

{

const int base = 10;

int result = 0;

int remain = 0;

do

{

remain = num % base;

result *= base;

result += remain;

} while( num /= base);

return( result );

}

int main()

{

int n;

printf( "Enter a value:\t" );

scanf( "%d", &n );

printf( "Reversed:\t%d\n", RevNum( n ));

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to reverse a digit 123?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How to code a program to print 123 894 765 when input is 123 456 789?

#include &lt;stdio.h&gt; int main (void) { puts ("123 894 765"); return 0; }


Is 123 in Decimal System equal to 1111011 in binary system?

The rightmost digit represents how many 1s (in this example 1) 1 The next digit left represents how many 2s (in this example 1) 2 The next digit left represents how many 4s (in this example 0) 0 The next digit left represents how many 8s (in this example 1) 8 The next digit left represents how many 16s (in this example 1) 16 The next digit left represents how many 32s (in this example 1) 32 The next digit left represents how many 64s (in this example 1) 64 Total 123


How do you separate digits in c plus plus?

Repeatedly divide the number by 10 and store the remainder (the modulo). By way of an example, if the number were 12345: 12345 % 10 = 5 (first digit) 12345 / 10 = 1234 1234 % 10 = 4 (second digit) 1234 / 10 = 123 123 % 10 = 3 (third digit) 123 / 10 = 12 12 % 10 = 2 (fourth digit) 12 / 10 = 1 (fifth digit) This algorithm forms the basis of number reversals. The following function demonstrates the most efficient way of reversing any number in the range -2,147,483,648 to 2,147,483,647, inclusive. int RevNum( int num ) { const int base = 10; int result = 0; int remain = 0; do { remain = num % base; result *= base; result += remain; } while( num /= base); return( result ); }


C program to print 1 12 123 1234?

#include &lt;stdio.h&gt; int main (void) { puts ("1 22 333 4444 55555"); return 0; }


Write a shell script to print given number in reverse order in Unix?

# Algo: # 1) Input number n # 2) Set rev=0, sd=0 # 3) Find single digit in sd as n % 10 it will give (left most digit) # 4) Construct revrse no as rev * 10 + sd # 5) Decrment n by 1 # 6) Is n is greater than zero, if yes goto step 3, otherwise next step # 7) Print rev # if [ $# -ne 1 ] then echo "Usage: $0 number" echo " I will find reverse of given number" echo " For eg. $0 123, I will print 321" exit 1 fi n=$1 rev=0 sd=0 while [ $n -gt 0 ] do sd=`expr $n % 10` rev=`expr $rev \* 10 + $sd` n=`expr $n / 10` done echo "Reverse number is $rev"