squares

This is a discussion on squares within the C++ Programming forums, part of the General Programming Boards category; Is there a way to find the square of a number (e.g. x^2) instead of having to write y=x*x?...

  1. #1
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369

    squares

    Is there a way to find the square of a number (e.g. x^2) instead of having to write y=x*x?
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Research pow() in <math>, i.e.

    Code:
    z = pow(x, y);
    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Code:
    #include <iostream>
    #include <cmath> //need for pow() function
    
    int main()
    {
           int a, b, c;
    
          b = a * a; //I would recommend this method for finding a square
    
         cout << "Enter a base: ";
         cin >> a;
    
         cout << "Enter an exponent: ";
         cin >> b;
    
          c = pow(a, b); //I would recommend this if raising to uncertain power
    
         return 0;
    }
    
    //pow(x, y) is in the form x^y

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating an image of squares?
    By vopo in forum C# Programming
    Replies: 3
    Last Post: 10-21-2008, 10:15 AM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. pass error before char
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-26-2006, 11:00 AM
  4. Magic Squares!
    By ZAM777 in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2004, 03:34 PM
  5. perfect squares?
    By ahalya in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2001, 09:38 PM

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