Thread: finding out what two numbers go into a number with no remainder.

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    33

    finding out what two numbers go into a number with no remainder.

    I'm trying to make a program that will try to find two perfect square numbers(4, 9, 16, etc)(x, and y) that go into another number(z) with no remainder, then try to square root x and y as far as they go, while still being a whole number. for example, if I enter 32, if will see that 16 and 2 go into 32 evenly, and that 16 can be square rooted to 4, and 4 to 2. but won't except, for example, 8 and for, because 8 can't be square rooted evenly. I have an idea where to go with this, like check to see if all the perfect squares multiplyed together equaled the number, but there's got to be an easyer algorythem then 1000+ if statements. if anyone has any ideas or links on where to go with this, I'd appreciate it alot, thanks.

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    some code help

    cin>>num;

    i=1;
    rem=1;
    while(rem!=0)
    {
    i=i+1;
    quo=num/i;
    rem=num%i;
    }
    cout<<"number : "<<num<<" = "<<quo<<"*"<<i;
    -

  3. #3
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    also i would like to know what do you want to do if the user enters 33...
    -

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    33
    33's not a perfect square, so the program would say something like, "that's not a perfect square". and thanks for the code, it'll give me some great ideas.

    here's some of the code I have now, but I think the syntax is all wrong.



    Pyth.h:
    #include <math.h>
    /*
    double PythRoot(double one, double two);
    double PythSquare(double one, double two);
    double PythSide(double one, double two);
    double PythSideSquare(double one, double two);
    I origonally had these included, but I took them out and they made no difference, so here they are.
    */


    double PythRoot(double one, double two)//finds the length of the hypotenuse plain and simple
    {
    one = pow(one, 2);
    two = pow(two, 2);
    one = one + two;
    two = sqrt(one);
    return two;
    }
    double PythSquare(double one, double two)//finds the length of the hypotenuse befre it is square rooted into a simpler form. Used for Simplifying roots.
    {
    one = pow(one, 2);
    two = pow(two, 2);
    one = one + two;
    return one;
    }
    double PythSide(double one, double two)//finds the length of a side of a right triangle when only the hypotenuse and another side are advailable.
    {
    one = pow(one, 2);
    two = pow(two, 2);
    one = two - one;
    two = sqrt(one);
    return two;
    }
    double PythSideSquare(double one, double two)//does the above, but does not square root it.
    {
    one = pow(one, 2);
    two = pow(two, 2);
    one = two - one;
    }
    double PythSimp(int i, double one, double two)
    {
    one = one * one;
    two = two * two;
    one = one + two;
    for(i=1; %(one/i)<1; i++) // I don't think the middle statement is correct
    {
    two=one/i;
    }
    return two;
    }



    Pyth.cpp:


    #include <iostream.h>
    #include "Pyth.h"//path changed
    int main()
    {
    double one, two, hyp, side, i;
    cout << "enter in the length of a side, then the hypotenuse";
    cin>>one>>two;
    cout << "the hypotenuse square should be"<<PythSquare(one, two)<<"now, the next number is our lucky number, it should be the number on the left, simplifyed, let's pray."<<PythSimp(i, one, two)<<endl;
    }

    also, on my if statement of the last function of Pyth.h when it says
    for(i=1; %(one/i)<1; i=i+1)
    how do I make is stop when i reaches 144?

    thanks again for help
    Last edited by Dummies102; 02-25-2002 at 11:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rounding numbers
    By maple23 in forum C Programming
    Replies: 3
    Last Post: 05-26-2008, 12:33 AM
  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. Finding the lowest number of a certain input
    By theorbb in forum C Programming
    Replies: 26
    Last Post: 04-17-2006, 02:36 AM
  4. finding the decimal part of a number
    By Geo-Fry in forum C++ Programming
    Replies: 13
    Last Post: 07-31-2003, 12:43 PM
  5. Determining if a number has a remainder?
    By Captain Penguin in forum C Programming
    Replies: 3
    Last Post: 09-01-2001, 07:07 AM