/*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);
}
You write the number and then follow it with the digits in reverse order.
Reference:cprogramming-bd.com/c_page2.aspx# reverse number
no thanks
unsigned reverse (unsigned num) { unsigned rev = 0; while (num) { rev *= 10; rev += num % 10; num /= 10; } return rev; }
write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
In python, type the following into a document. NOTE: Sentences following a # symbol are comments, and are not necessary for the program to run. #!/usr/bin/python #This program takes a input from a user and reverses it. number = input("Type a number: ") #This takes input from a user. a = len(number) #This finds the length of the number reverse = "" #This sets the variable reverse to an empty string. for i in number: a = a-1 #The places in a string start from 0. The last value will be the length minus 1.reverse = reverse + number[a] #Makes the number's last digit the new string's first. print("The reverse of", number, "is", reverse + ".") #prints the resulting string. This program will take any sequence of characters and reverse them. The final value is a string, but if an integer is needed, one needs only to add the line reverse = int(reverse) above the print statement. However, this will stop the program from being able to reverse strings, as it is not possible to convert a string to an integer if it is not a number.
#include <stdio.h> int main(int argc, char **argv) { if (argc<1) { printf("Usage: %s number\n",argv[0]); return -1; } int digits=1, i=atoi(argv[1]); while (i/=10) ++digits; printf("%d\n",digits); }
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); }
To write the number in digits, you would write it like this: 95,032,659,004.
8,400,000.00
abdulrahman