Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversing a 3-digit number #2242

Open
savinineeli6 opened this issue Oct 20, 2023 · 3 comments
Open

Reversing a 3-digit number #2242

savinineeli6 opened this issue Oct 20, 2023 · 3 comments

Comments

@savinineeli6
Copy link

savinineeli6 commented Oct 20, 2023

Hello, I would like to work on a problem of reversing a '3-digit ' number in C language. Can you please assign this issue to me?

@Intruder9211
Copy link

Sure, I can assign the issue of reversing a 3-digit number in C language to you. Here is a possible approach to solving the problem:

Declare two integer variables: number and reversed_number.
Initialize reversed_number to 0.
While number is greater than 0, do the following:
Calculate the last digit of number using the modulus operator (%).
Multiply reversed_number by 10.
Add the last digit of number to reversed_number.
Divide number by 10.
Return reversed_number.

Source code:

#include <stdio.h>

int reverse_number(int number) {
int reversed_number = 0;

while (number > 0) {
reversed_number = reversed_number * 10 + number % 10;
number = number / 10;
}

return reversed_number;
}

int main() {
int number = 123;

int reversed_number = reverse_number(number);

printf("The reversed number is %d\n", reversed_number);

return 0;
}

@Urva2
Copy link

Urva2 commented Oct 30, 2023

i would like to fix this issue. pls assign me this issue because as beginner this is very boost myself.

@akshatvermavi
Copy link

Please assign it to me its my last date to contribute for hackatoberfest @Intruder9211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants