Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7430971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:13:23+00:00 2026-05-29T09:13:23+00:00

Firstly, this is a homework assignment, and I am very new to programming in

  • 0

Firstly, this is a homework assignment, and I am very new to programming in C. What I am trying to accomplish is the user puts in an integer, and then each individual digit of that integer is printed on a new line, like below:

Enter integer: 1234
The digits are:
1
2
3
4

My problem is that whatever integer you input, for some reason a 7 and a 4 are added on to the end. Below is my code and an example of the problem:

#include <stdio.h>
#define Success 0

int main()
{ int integer;
  int reverse;
  int digit;

  printf("Enter Integer: ");
  scanf("%d", &integer);

  /* Reverse the numbers in the integer */
  while (integer != 0) { 
    digit = integer%10;
    reverse = (reverse * 10) + digit;
    integer = integer / 10;
    }

  /* Print the numbers of the reverse integer, in reverse order */
  while (reverse != 0) {
    digit = reverse%10;
    printf("%d\n", digit);
    reverse = reverse / 10;
    }

return Success;
}

Example of problem:

Enter Integer: 12345
1
2
3
4
5
7
4

Anyone have any ideas as to what might cause this outcome? By printing reverse I have narrowed it down to a problem with the first while loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:13:24+00:00Added an answer on May 29, 2026 at 9:13 am

    Reverse is not initialized. This means there could be any value in that variable when you start touching it. Set it to 0 after you declare it and see what happens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly I'm very new to web development so forgive me if this is a
I'm programming an application for Windows Phone 7. This application firstly sends, and then
Firstly I am new to android and Java so this is a beginners question.
Firstly this is not a homework question. I am practicing my knowledge on java.
Firstly I did my homework, I've checked this: How to store 2D Array coordinates
Firstly, I'm new to Android (so I apologize if this question is ignorant) but
Firstly, I've got functions like this. void func1(); void func2(); void func3(); Then I
Firstly apologies if this is really simple but I have spent hours trying and
Ok, firstly this is not about forms this is about consistent layout as a
Firstly: I am totally a newbie for this kind of work. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.