Thread: Beginner in C facing problem

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    INDIA
    Posts
    13

    Unhappy Beginner in C facing problem

    Hi!
    Could you plz help me in the following question:
    "Write an interactive program to demonstrate the process of multiplication.The process should ask the user to enter two 2-digit numbers(integers) and print the product of the integers as shown below:

    45
    x 37
    --------------
    315 (7x45)
    135 (3x45)
    ---------------
    1665 (Add them)
    ---------------

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    For the example provided, you'd need to split the bottom multiplier 37 into it's component pieces 3 and 7. This can be done with some simple math using division (/) and modulus (&#37 operators: What is 37 / 10? What is 37 % 10?
    "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

  4. #4
    Registered User
    Join Date
    Aug 2007
    Location
    INDIA
    Posts
    13
    #include <stdio.h>
    void main()
    {
    int ax,by,a,b,c,d,e;
    printf("Enter any two 2-digit integers");
    scanf("&#37;d %d",&ax,&by);
    c=ax*(by-10*b);
    d=ax*((by-y)/10); /*here I have broken 37 as
    scanf("%d %d",&c,&d); 3*10+7 i.e" by=10b+y"*/
    e=c+10*d;
    printf("The product is %d",e)
    Last edited by paushali; 10-30-2007 at 11:47 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 12-13-2008, 09:32 AM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  4. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  5. beginner function problem
    By dellebelle751 in forum C++ Programming
    Replies: 7
    Last Post: 10-30-2002, 07:12 PM