(what will be the output someone please help me out thanks)
if (abs(x) < xmin) x = (x > 0) ? xmin : -xmin;
This is a discussion on Compound Statement within the C Programming forums, part of the General Programming Boards category; (what will be the output someone please help me out thanks) if (abs(x) < xmin) x = (x > 0) ...
(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 helpsCode:if (abs(x) < xmin) { if(x > 0) { x = xmin; } else { x = -xmin; } }![]()
Code - functions and small libraries I use
__________________________________________________ __________________________________________________ ______________
It’s 2013 and I still use printf() for debugging.
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?![]()
Code - functions and small libraries I use
__________________________________________________ __________________________________________________ ______________
It’s 2013 and I still use printf() for debugging.
#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 timeIt 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; }
Code - functions and small libraries I use
__________________________________________________ __________________________________________________ ______________
It’s 2013 and I still use printf() for debugging.