Answer to Question #19215 in C++ for baby_dawn

Question #19215
write a C++ function clip (lo,x,hi) that returns lo if x is less than lo; hi if x is greater than hi; and x otherwise for this problem you can assume that lo<hi.
1
Expert's answer
2012-11-21T11:17:56-0500
#include <stdio.h>
#include <conio.h>

int clip(int lo, int x, int hi)
{
if (lo < hi)
{
& if (x < lo)
& return lo;
& if (x > hi)
& return hi;
}
return x;
}

void main()
{
printf("%d\n", clip(8, 2, 11));
printf("%d\n", clip(2, 9, 6));
printf("%d\n", clip(5, 1, 4));
printf("%d\n", clip(7, 8, 10));
getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS