Can a scanf function see a number input "1234" as 4 separate numbers?

This is a discussion on Can a scanf function see a number input "1234" as 4 separate numbers? within the C Programming forums, part of the General Programming Boards category; Here's my answer to my C course question. I'm proud, even though it's only small. It does what I think ...

  1. #31
    Registered User
    Join Date
    Nov 2009
    Posts
    9
    Here's my answer to my C course question. I'm proud, even though it's only small. It does what I think the original question is:

    Code:
    	EE Programming Fundamentals Lab 3
    	Question 4
    */
    
    #include <stdio.h>
    
    int main(void)
    {
        int inNum, outNum[4];
    
        do {
            printf("Enter a 4-digit number: ");
            scanf("%d", &inNum);
        } while ((inNum < 1000) || (inNum > 9999));
        
        outNum[0] = inNum/1000;
        inNum -= 1000*(inNum/1000);
        
        outNum[1] = inNum/100;
        inNum -= 100*(inNum/100);
        
        outNum[2] = inNum/10;
        inNum -= 10*(inNum/10);
        
        outNum[3] = inNum;
        
        printf("Your number is %d %d %d %d.\n",outNum[0], outNum[1], outNum[2], outNum[3]);
    
        return 0;
    }
    
    /*End of programme*/

  2. #32
    Registered User
    Join Date
    Nov 2009
    Posts
    9
    Output:

    Code:
    [ec09411@dil015 3_4]$ ./Lab3_4
    Enter a 4-digit number: 6546
    Your number is 6 5 4 6.
    [ec09411@dil015 3_4]$

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12:49 PM
  2. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  3. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21