Thread: removing a part from a number

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    removing a part from a number

    have to write code that lets the user enter a 5 digit's number.
    after that it must remove the 3th digit from the number and printf the rest of the number
    this is what i written but it's not good , because it ask for evry digit individually .

    Code:
    #include <stdio.h>
    #include <conio.h>
    void main()
    {
    clrscr();
    int a,b,c,d,e;
    printf("Enter 5 digits number:\n");
    scanf("&#37;d%d%d%d%d",&a,&b,&c,&d,&e);
    printf("After removing the 3th digit the number is:\n%d%d%d%d",a,b,d,e);
    getch();
    }
    Last edited by samsung; 10-24-2007 at 03:31 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You can substitute char for int in that code (along with %c instead of %d) and it should work.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    void main is also wrong, see the FAQ http://faq.cprogramming.com/cgi-bin/...&id=1043284376

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Although, I'm fairly sure that's not the solution the teacher was looking for. Think of a mathematical way to do this with a single large number, instead. It can be done, fairly easily with integer math.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    Quote Originally Posted by hk_mp5kpdw View Post
    You can substitute char for int in that code (along with %c instead of %d) and it should work.
    thanks for your reply it worked like charm

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    Quote Originally Posted by zacs7 View Post
    void main is also wrong, see the FAQ http://faq.cprogramming.com/cgi-bin/...&id=1043284376
    yes but i am using the older version of borland 3.1 for DOS if i am not mistaking .
    and it gives compile error's if i don't use it like this.

    Quote Originally Posted by matsp View Post
    Although, I'm fairly sure that's not the solution the teacher was looking for. Think of a mathematical way to do this with a single large number, instead. It can be done, fairly easily with integer math.

    --
    Mats
    any advices , don't need code just tell me what i have to look for refrence, thanks

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Why are you using such and old compiler then?

    I think matsp was hinting at -- read one number and do a bit of math on it do remove the 3rd digit? Which is easy if you remember basic maths

    Code:
    tens-of-thousands    thousands hundreds tens ones
    5                    4         3        2    1
    Last edited by zacs7; 10-24-2007 at 04:20 PM.

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    Quote Originally Posted by zacs7 View Post
    Why are you using such and old compiler then?

    I think matsp was hinting at -- read one number and do a bit of math on it do remove the 3rd digit?
    that is the compiler we use .
    at home i use DEV-C++ . i make the code in DEV i compile it run it it's all ok.
    but when i load it in borland it start giving me errors .
    so that is why i must use borland , the GUI is so uglly .

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you're writing code that can compile in one compiler but not another, then it's probably not portable code.

    What kind of code were you writing? What functions were you using? What errors were you getting?

    Were they errors to the effect of this?
    Code:
    program.o: undefined reference to `clrscr'
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting part of a number
    By h3ro in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2009, 12:44 PM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  3. Replies: 2
    Last Post: 11-18-2006, 03:31 AM
  4. Perfect number...
    By Argo_Jeude in forum C++ Programming
    Replies: 8
    Last Post: 07-12-2005, 01:53 PM