tags:

views:

96

answers:

2

The title says it all actually.

In a simple way, i have an array of 10 values for example..and i would like to multiply each value with 5. Can i actually just do the following?

for (i = 0 ; i <10 ; i++)   
   {
x[i]=x[i]*5;
}

And what about getting square for values in the array and be stored back into the same array? As in I want x[i]=x[i]*x[i].

Can I actually just do the multiplication like that? I tried a couple of combination but it didnt really work..hope someone can help out! Thanks!

+1  A: 

This is perfectly fine.

Eiko
what about square root? Can I do x[i]=sqrt(x[i]*x[i]); ? With math.h at the top of course..Thanks..
esther
x[i] = sqrt(x[i]); otherwise you will get abs(x[i]) ;-)
Eiko
hehe actually i wanted to get the absolute value..was just wondering if such multiplication is right. ;) THANKS!
esther
If you want abs, use the abs function. Or multiply by -1 if needed ;-)
Eiko
+1  A: 

edited now that the language has been specified


Yes, this "just works" in C.

Can you post more about the errors you're seeing so that we can try to help you out?

Stephen Canon
C language please hehe..
esther
i got it already hehe, actually u guays already answered my doubts :)
esther