help with this problem

This is a discussion on help with this problem within the C++ Programming forums, part of the General Programming Boards category; Problem 3. Write a complete program that implements the following algorithm that computes the greatest common divisor of two given ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    2

    help with this problem

    Problem 3. Write a complete program that implements the following algorithm that computes the greatest common divisor of two given positive integers. For example, if 441 and 252 are input, then the program should print that 63 is their greatest common divisor:

    Algorithm 3.1 The Euclidean Algorithm
    To find the greatest common divisor gcd of two positive integers m and n:
    1. Subtract m from n repeatedly until n<m.
    2. Interchange the values of m and n.
    3. Repeats steps 1-2 until m=0
    4. Then n is the greatest common divisor of the two original numbers

    Problem 4. Write a program that returns the factorial of 150. The output should be 2 3 5 5

    Problem 5. Write a program that inputs a positive integer n and then prints a triangle of asterisk n lines high 2n-1 columns wide. For example, if the input is 5 then the output should be.

    can give a code for this thanks

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by mumay View Post
    can give a code for this thanks
    Yes, I could, but I don't feel like doing homework for a lazy student.

    Try it on your own first and find out where you get stuck. Ask specific questions if you must, but make sure it's you doing the work. If you absolutely hate C++, don't take a course on it.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Problem 3:
    The internet is full of the implementations of this algorithm. If you can't program following the outlined steps, you could google.

    Problem 4:
    The program is not supposed to calculate factorial (quite hard for 150 ) but factors. Hint: you may need to find out if a value is divisible by 2, 3, 4 etc.

    Problem 5:
    No hints for printing asterisks.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    2
    Quote Originally Posted by MacGyver View Post
    Yes, I could, but I don't feel like doing homework for a lazy student.

    Try it on your own first and find out where you get stuck. Ask specific questions if you must, but make sure it's you doing the work. If you absolutely hate C++, don't take a course on it.
    im trying our teacher did not tech us how to do this im doing it a whole day im reading books but it wont work im having hard time of it i had already try it but always had error so pls help me

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    If you've tried it but gotten errors, feel free to post your best attempt along with the errors it gives you and somebody can probably help you with them. Make sure to post the code in [code][/code] tags.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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