Thread: Seperating Integers

  1. #1
    Registered User Melon's Avatar
    Join Date
    Jan 2003
    Posts
    13

    Seperating Integers

    Hello everyone,
    I'm looking to write a program that will take a five digit number and proceed to give the sum of the intergers, the average (as a float), the smallest integer and the largest interger. My main problem is just figuring out how to seperate the indivdual integers from the one. I believe I will be able to figure the rest out once that can be done. Thanks.
    Ten out of ten people die, so don't take life so seriously.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Simple. Just prompt five times for numbers, or use a single scanf line to grab five numbers.

    printf("Enter five numbers, each seperated by a space, and hit enter: ");
    scanf("%d %d %d %d %d", &var1, &var2....and so on...);

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Melon's Avatar
    Join Date
    Jan 2003
    Posts
    13
    yes that would be very easy, although that is one of the objectives of my program, to actually seperate the digits from the larger number.
    Ten out of ten people die, so don't take life so seriously.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Melon
    yes that would be very easy, although that is one of the objectives of my program, to actually seperate the digits from the larger number.
    Ah, you should have said that in the first place. It pays to be precise.

    Here's a thought:

    number = 12345
    digit1 = number % 10
    number /= 10
    digit2 = number % 10
    repeat as needed

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User Melon's Avatar
    Join Date
    Jan 2003
    Posts
    13
    Sorry about that quzah, my mistake. A little habit that I need to break most likely. We'll you were right, that's for sure. I thank you for your help. Hopefully one day I shall feel the pleasure of being able to help other programmers, but for now I'm just a lowly beginner. Thank you again quzah, best of luck to you in the future.
    Ten out of ten people die, so don't take life so seriously.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seperating integers and a string into tokens
    By msatyani in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 07:20 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  4. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-29-2008, 11:35 PM
  5. Replies: 6
    Last Post: 08-04-2003, 10:57 AM