Thread: What's the last digit??

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    What's the last digit??

    Hello you guys. This is my first program that im writing In C and i really need some help. Im suppose to write a program that reads an integer value and outputs the value of its last digit as an English word using ONLY if statements but im not sure how to scan each integer and mark the last digit. I'm also not sure how big the digits will be, is there a limit for integers in C? like could it only be like 3000 or something?

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    32
    While I don't have your course syllabus in front of me, I can safely say you're probably making it too hard on yourself. No need to go character-by-character. Read the integer as an actual integer (however you learned to do that), then use the modulus (%) operator to determine the last digit, base 10.

    i.e.
    Code:
    int thenumber;
    int lastdigit;
    
    thenumber = read_number_somehow();
    lastdigit = thenumber%10;
    Your question about maximum integer size in C is certainly valid, however if this is your very first C program, it isn't immediately relevant and I'd just wait until that is properly explained in the course of your instruction, whether it's self-taught or otherwise.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying the rightmost digit of a positive number
    By randoms4ever in forum C Programming
    Replies: 6
    Last Post: 10-04-2009, 07:50 AM
  2. error msg instead of the result so far
    By maybabier in forum C Programming
    Replies: 25
    Last Post: 03-20-2009, 02:45 PM
  3. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  4. newbie programmer - needs help bad.
    By hortonheat in forum C Programming
    Replies: 17
    Last Post: 10-20-2004, 05:31 PM
  5. Roman number converter
    By BalanusBob in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2002, 06:29 AM