Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pow() square number

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
#include <stdio.h>
#include <math.h>
void main()
{
int x, y, z;

/* example */

x = 36;
y = 49;

z = (x + y) * (x + y ); /*these 2 calculations will */
/* produce the same result,*/
z = pow(x+y,2); /* is this the correct way to use */
/* pow()and is it valid in ANSI C */

printf(&quot; The value of z is %d&quot;,z);
}

thanks

 
It is valid BUT DO NOT do it. This will work slower.
In theory better do:
x = 36;
y = 49;
xy = x + y;
z = xy * xy;
But in practic optimizer will do this job for you, so don't bother your mind with this kind of optimization.
z = (x+y)*(x+y); will for just fine and as quick as your computer can.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top