#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();
}
#include <stdio.h> int main (void) { puts ("123 894 765"); return 0; }
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
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 ); }
#include <stdio.h> int main (void) { puts ("1 22 333 4444 55555"); return 0; }
# 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"
With 123 digits you can make 123 one-digit numbers.
123
123
123
1+2+3=6 1x2x3=6 123
You write it as 123.
One good fact about the number 1089 is: pick a 3 digit number (they cannot be the same) i.e 123 reverse it 321 take the smallest amount from the largest 321-123=198 take the answer and reverse it 891 then add that number to the answer of the subtraction 891+198=1089 no matter what 3 numbers you use you will always end up with 1089 for the answer.
1, 12, 23, 34, 45, 56, 67, 78, 89,101, 112, 123, 134, 145, 156, 167, 178, 189 and so on
Just 6: 123 132 213 231 312 321
123%
123
CXXIII