#include<conio.h>
#include<stdio.h>
void main()
{
int d,m,r=0;
clrscr();
printf("\n Enter the value for m ");
scanf("%d",&m);
do
{
d=m%10;
m/=10;
r=(r*10)+d;
}while(m!=0);
getch();
}
An example of an algorithm that will reverse a number is written as such, digit reverse(num), while (num>0) then, digit =num%10. This particular algorithm divides a number by 10 until the original number from the LSD is found.
main() { int num=0xABCD; printf("%x\n",num); int rev=0x0; int digit=0x0; while(num!=0x0) { digit=num%0x10; rev = rev*0x10 +digit; num=num/0x10; } printf("%x\n",rev); }
#include #include void main() { int rev num=0; while(num>0) { rev num=rev num*10+num%10; num=num%10; } return rev_num; } int main(); { int num=4562; printf("reverse of number is%d",reverse digit(num)); getch(); return o; }
public class StringReverseExample { public static void main(String[] args) { int num=1001; int n=num, rev; while(num!=0) { int d=num%10; rev= (rev*10)+d; num=num/10; } System.uot.println(rev); } }
there could be a part in it like this: int num, digit; int count [10]; do { digit = num%10; num != 10; ++count[digit]; } while (num);
#include<iostream> // forward declarations... unsigned reverse (unsigned, const unsigned base = 10); bool is_palindrome (const unsigned); // the program... int main (void) { const unsigned max {500}; const unsigned min {100}; std::cout << "Palindromes from " << max << " to " << min << std::endl; for (unsigned num {max}; num>=min; --num) { if (is_palindrome (num)) { std::cout << num << std::endl; } } } // Returns the reverse of a number using the given base (default: base 10) // Note: trailing zeroes do not become leading zeroes so reverse (100) returns 1 not 001. // However, the reverse of 0 is obviously 0. unsigned reverse (unsigned num, const unsigned base /* = 10 */) { unsigned rev {}; // zero-initialised while (num) { rev *= base; rev += num % base; num /= base; } return rev; } // If the reverse of a number is the same number, that number is a palindrome. // All single-digit numbers are palindromes, including 0. bool is_palindrome (const unsigned num) { return num == reverse (num) ; }
int sum_digits (int num) { int sum; sum =0; while (num) { sum += num % 10; num /= 10; } return sum; } Example usage: int main (void) { int i; printf ("Input a 6-digit number: "); scanf ("%6d", &i); printf ("The sum of the digits in %d is: %d\n", i, sum_digits (i)); return 0; }
To check if a number is a palindrome, reverse the number and see if it is equal to the original number. If so, the number is a palindrome, otherwise it is not. To reverse a number, use the following function: int reverse(int num, int base=10) { int reverse=0; while( num ) { reverse*=base; reverse+=num%base; num/=base; } return(reverse); }
function complement(num, base){ var result = 0, column = 0; if(base < 2) return null; while(num > 0){ digit = num % base;comp = base - 1 - digit;result += comp * Math.pow(base, column);column++;num -= digit;num /= base;} return result; }
100.
//program to print the reverse of a number within 'int' range//#include#includevoid main(){int num,rem,sum=0;printf("\n Enter a number : ");scanf("%d",&num);printf("\n\n Reverse is : );while(num>0){if(num
/*Reverse the digits of a number,Gankidi*/ #include<stdio.h> void main(void) { int num,sum=0,i,rem; printf("Enter a number"); scanf("%d",&num); while(num>0) { rem=num%10; num=num/10; sum=sum+(rem*10); } printf("the reverse number is %d",sum); }