(what will be the output someone please help me out thanks)
if (abs(x) < xmin) x = (x > 0) ? xmin : -xmin;
Printable View
(what will be the output someone please help me out thanks)
if (abs(x) < xmin) x = (x > 0) ? xmin : -xmin;
If you indent it, the truth will be revealed!
The first line of code is simple.Code:if (abs(x) < xmin)
x = (x > 0) ? xmin : -xmin;
The second line of code says.
If x>0, then assing xmin to x.
If condition x>0 is false (thus x <= 0 is true ) , then assign -xmin to x.
In other (code) words
Hope this helps :)Code:if (abs(x) < xmin)
{
if(x > 0)
{
x = xmin;
}
else
{
x = -xmin;
}
}
hey thanks dear friend for explaining the code in detail but when i run it using values it does not give anything
Why don't you post the code you tried so that we can see it too? :)
#include<stdio.h>
main()
float xmin,x;
x=5.6;
if (abs(x) < xmin)
if(x > 0)
x = xmin;
else
x = -xmin;
i did not include the braces as it does not accept here with braces assume i put the braces
Ok first wrap your code in code tags next time ;) It is easy. You write
[key] /* Your code here */ [/key] Replace key with code in order this to work
In your code you do not give a value to xmin, so your flow of code will not go into the if structure you have.
Also if you want to see something put some printf's
Finally you usually write
Code:int main(void)
{
....
return 0;
}