English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

can somone tell me the algorythm of this problem
i wanna print the inverse of the input number
4 example: 123 ===> 321

2006-08-06 21:01:08 · 9 answers · asked by avril_from_canada_li2 1 in Computers & Internet Programming & Design

9 answers

// recursive solution for n!=0
void printrev(unsigned int n) {
if(n == 0) return;
printf("%d", n%10);
printrev(n/10);
}

2006-08-06 21:39:42 · answer #1 · answered by swami060 3 · 1 0

first of all, i haven't touched the programming long time ago and only trained in C++.. But here is some idea if might help.

you can choose the number to enter one by one instead of awhole..
for example,

123, you can make it enter 1 & 2 & 3 and assign each number to a cell like 1 to cell A, 2 to cell B, 3 to cell C.. then you can write the program to appear reverse.. that is display cell C, cell B and cell A.

so first the program will ask "enter first number" then you enter 1.
then "enter second number" then you enter 2.
so on..

I am not sure it will work but the idea is there..

2006-08-06 21:09:45 · answer #2 · answered by Cool Z 5 · 0 0

upload the 8 to the different side. this can provide 15x-3x=24. in view that 15x and 3x the two have an x in them, you could integrate them ensuing in 12x = 24. Now, you in basic terms resolve for x with the aid of dividing 24 with the aid of 12. to that end, x equals 2. examine your paintings, 15(2) - 8 - 3(2) = sixteen that's 30 - 8 - 6 = sixteen....and sixteen = sixteen. you're completed!

2016-09-29 00:00:14 · answer #3 · answered by wiemer 4 · 0 0

In Java, u have built method to do so. Here is the solution:

StringBuffer sb = new StringBuffer("123").reverse();
System.out.println(sb.toString());

2006-08-06 22:19:31 · answer #4 · answered by Ravi K 1 · 0 0

hers the c pusdo code i guess will work:

int n = 0;
int num = 123 ; // your number here

while ( num >= 0 )
{
temp = num % 10; //get the last digit of your num
num = num/10; //remove the last digit from the num

printf("%d",temp);
}

For strings i guess recursion works better ........

2006-08-06 21:30:45 · answer #5 · answered by kunal c 1 · 0 0

first ya get some honey, some live chickens, and some barb wire, a smoking hot woman and get ya freak on

2006-08-06 21:06:09 · answer #6 · answered by Anonymous · 0 0

n=123
m=0
a=0
while(n!=0){
a=n%10
m=m*10+a
n=n/10
}
print m

2006-08-06 22:10:49 · answer #7 · answered by Anonymous · 0 0

#include /* strrev.c */
#include
#include

char * strrev(char * string) {
int length = strlen(string);
char * result = malloc(length+1);
if( result != NULL ) {
int i,j; result[length] = '\0';
for ( i = length-1, j=0; i >= 0; i--, j++ ) result[j] = string[i];
}
return result;
}

int main() { char msg1[] = "Hello world!";
char * msg2; msg2 = strrev(msg1);
printf("Reversing finished!\n"); //@{}@XPC {local variables clobber stack!}
printf("msg2=`%s'\n", msg2);
free(msg2);
return 0; }

2006-08-07 00:03:54 · answer #8 · answered by sudhars_mail 1 · 0 0

idk

2006-08-06 21:03:27 · answer #9 · answered by lil brat 1 · 0 0

fedest.com, questions and answers