hi! i'm beginning to like C, i find it very challenging. and i have this problem, that confuses me here:
Construct a C that will accept 5 digit number, determined the reversed number and display the message "equal" if the original 5 digit number and the reversed number is equal, otherwise display "not equal".

- what confuses me is that how can i determined the reversed number. i have this condition,

input 12345, the reversed number is 54321

2
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by jonsca

Hint: get the user's input in the form of a char array (use fgets to read the line of text).

input 12345;
scanf("%c,%c,%c,%c,%c",&n1,&n2,&n3,&n4,&n5);
printf("the reversed number is:%c,%c,%c,%c,%c",n1,n2,n3,n4,n5);

is this what you mean?

I was thinking more along the lines of the following for input

``````char number[6];
fgets(number,6,stdin);``````

Theoretically yours works, but look at the third line and the number is being printed out in the same order. I suppose the comparisons don't take any more work your way.

You'll have to watch that you put in the commas, though, as that's what your scanf is calling for.

hi! if i get the original number and the reversed number how can make the condition? i have this condition correct me if i have wrong.

if (original number == reversed number)

how can i know if the original and the reversed are equal?
if i have 12345 and the reversed is 54321, how can you determined if they equal or not? by getting the sum of the two numbers or what? please help me

If you have an array of characters |1|2|3|4|5|\0| you know the third character (at index 2) is always going to be the same, so compare indexes 0 and 4 along with indexes 1 and 3. If the number of matches is equal to 2, they are the same. This may seem more tedious to do, but try using your method on a 1000 digit number.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.