Thread: Making quadrat on c programming language

  1. #1
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112

    Making quadrat on c programming language

    Does anybody know how to make a quadrat on a number or variabel? I searching it on anyweb but i didnt find the solution, please help! I wanna making a math calculation using c programming and by myself quadrat is vital thing i must know ......
    sorry for my bad english

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    What is a quadrat?

    Do you maybe mean a square root (Square Roots) or a square (x2)?

    Code:
    #include <math.h>
    
    void test(void)
    {
       double res = sqrt(x); 
    }
    sqrt - C++ Reference

    For x2 you may as well just do x*x. For xn

    Code:
    #include <math.h>
    
    void test(void)
    {
       double res = pow(x, n); 
    }
    pow - C++ Reference

    Sorry if I misunderstood your question. If you do actually mean this: Quadrat - Wikipedia, the free encyclopedia then no I don't have a clue how to represent it in C

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quadrat - Wikipedia, the free encyclopedia ? You do kind of have to be careful to know what you want, or you risk communicating a different idea. What are you doing again?

  4. #4
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    yeah that is what i mean
    in my country language, square root are called kuadrat, so i think kuadrat = quadrat = square root
    what if x with square root 3 or more?
    and must we using double res = pow(x, n);

    Quote Originally Posted by smokeyangel View Post
    What is a quadrat?

    Do you maybe mean a square root (Square Roots) or a square (x2)?

    Code:
    #include <math.h>
    
    void test(void)
    {
       double res = sqrt(x); 
    }
    sqrt - C++ Reference

    For x2 you may as well just do x*x. For xn

    Code:
    #include <math.h>
    
    void test(void)
    {
       double res = pow(x, n); 
    }
    pow - C++ Reference

    Sorry if I misunderstood your question. If you do actually mean this: Quadrat - Wikipedia, the free encyclopedia then no I don't have a clue how to represent it in C

  5. #5
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    sorry, i didnt know the correct english for square root,

    Quote Originally Posted by whiteflags View Post
    Quadrat - Wikipedia, the free encyclopedia ? You do kind of have to be careful to know what you want, or you risk communicating a different idea. What are you doing again?

  6. #6
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    ok so you want the square root and thats it, or do you want other roots, like cube root (cubed root of 27 = 3 meaning 3*3*3)

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    what if x with square root 3 or more?
    A cube root or nth root can be expressed mathematically as raising to a fractional power n^(1/3) or n^(1/6) for example. So use pow.

  8. #8
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    yeahhh, thats it.
    not only cube root, more of it i will use that
    like 64 = 2 meaning 2*2*2*2*2*2

  9. #9
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    Quote Originally Posted by whiteflags View Post
    So use pow.
    i see that! by the way what is that "pow" acronym?
    and how i use it with a simple code?
    when i see "double res" thing, it makes me confused,
    must it exist before pow or doesnt must?

  10. #10
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    yeah go with what WhiteFlags said

    Code:
    double res = pow(x, (1/n));
    is the same as
    Code:
    double res;
    res = pow(x, (1/n));
    where x is your whole number, and the n is the # of roots

    ie x=27 n=3 res would =3, or x=64 n=6 res would be n=6 res would be 2.

  11. #11
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    Quote Originally Posted by Crossfire View Post
    yeah go with what WhiteFlags said

    Code:
    double res = pow(x, (1/n));
    is the same as
    Code:
    double res;
    res = pow(x, (1/n));
    where x is your whole number, and the n is the # of roots

    ie x=27 n=3 res would =3, or x=64 n=6 res would be n=6 res would be 2.
    hemm,
    is that "x" thing, are declared variables by using int, float?
    and "n" thing are constant?
    res = result, right?
    if i wanna print to the screen, would it be like this,
    printf("The Result %d", res);

  12. #12
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    you can have the "user" give both X and N, so they could choose regular square root of 9(x=9 n=2), or cubed root of 27 (x=27 n=3) quad root of 1296 (x=1296 n=4) ect

    yes x, n, res all variables
    x = big number
    n = #of roots
    res = result

    and make sure to have all doubles, so you get the decimals if not a true root, either that or use type casting to divide and get the decimals
    Last edited by Crossfire; 12-29-2012 at 08:09 AM.

  13. #13
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    The best thing is to use doubles for all the numbers. It causes the least trouble. Values like 1.0 / 3.0 require the places after the decimal point too.

    The only thing you don't seem to know is that pow is a function from math.h. Might want to review your C book!

  14. #14
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    yeah i know, pow function is a function from math.h
    by the way, i know to use sqrt using header math.h
    but i didnt know how to make square root.
    doubles are both of int and float right? cool

  15. #15
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    doubles are both of int and float right? cool
    Doubles are basically the same as floats, just bigger. Integers have nothing to do with either float or double.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making Programming Language
    By valaris in forum Tech Board
    Replies: 3
    Last Post: 02-09-2009, 02:35 AM
  2. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 02:22 AM
  3. What's the Difference Between a Programming Language and a Scripting Language?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-15-2005, 04:46 PM
  4. Making a Regional Language..
    By Coder87C in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2004, 09:51 PM
  5. How would I go about making a scripting language...
    By gcn_zelda in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2003, 11:43 AM

Tags for this Thread