To reverse a given number

To reverse a given number

To reverse a given number? That's a weird question. Have you read the Forum Rules

Would this help you?. Use the function to adapt it to your own program

/* 
 * reverse_digit.c
 * a sample program to reverse the digits of a given number 
 */

#include <stdio.h>

void reverse_it(int value);   /* function prototype */

int main()
{
    int number;
    
    printf("Enter a number: ");
    scanf("%d", &number);
    
    printf("Here's the number reversed: ");
    reverse_it(number);  /* call to the reverse_it function */
    
    return(0);
    
}

/*
 * reverse_it function
 * parameter: accept an integer
 * return: nothing
 */
void reverse_it(int value)
{
    int rev;

    do    /* start loop  */
    {
        rev = value % 10; /* assigns to variable rev the remainder of the division value / 10   */
        printf("%d", rev); /* displays rev */
        value = value / 10; /* assigns to value the division value / 10 */
    }while(value != 0);  /* as long as this is true loop */
}

/* input--> Enter a number: 456 */
/* output--> Here's the number reversed: 654 */

Couldn't you just have described the method rather than spoon-feeding the OP an answer. I'm sure that answer is just going to get handed in without any more thought.

What are they going to do with their next assignment, just post it here and hope for the same thing.

@ Salem
I can see that you are right in your comment. And I apologize if I went wrong in a matter of
principles.
However I'm new to programming and most of the time I take these questions as a challenge to
me to learn if I can do it. Very often I ckeck the forum just to see if there's something
I can help with, and to be honest, there's not much I can do, since my level of knowledge is very limited. I beg to forgive my eagerness in a fast answer.

commented: No problem - Salem +5

Eagerness is good but you can still take the problem as a challenge, solve it but atleast keep the solution to yourself till the OP shows some effort.

Just try to help someone out without just pasting out the source code and you would know how it comes out to be. Helping someone without pasting the code and helping them in getting the concepts right is a far better help rendered, methinks. Try it, you really will love it.

And btw, Mr. Salem is actually a good guy, so I guess you are off the hook... ;)

> I beg to forgive my eagerness in a fast answer.
No problem :)

Doing the problems is fine (as ~s.o.s~ says), and is a good source of ideas for your own learning.

But the aim is to nudge (then push, then drag) the OP towards the answer based on what they've managed to do so far. Figuring out what they need (not what they want) can be tricky (especially since the OP only posted 5 words). Which is why we like to see code first, it allows us to tune the answer to the OPs level of experience.

Short snippets of code a few lines long explaining how a particular idea might look should be enough to get them going.

Sure, if they're still not getting it after several posts then it's time to roll a bit more code in front of them.

> Very often I ckeck the forum just to see if there's something I can help with
Please do - it's always good to have more contributors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.