Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. zad 7.33.c
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <time.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9. int clamp(int v, int lo, int hi)
  10. {
  11. int res;
  12.  
  13. if(v<lo)
  14. res=lo;
  15. else if(v>hi)
  16. res=hi;
  17. else
  18. res=v;
  19.  
  20. return(res);
  21. }
  22.  
  23. int main()
  24. {
  25. int num,up,down,temp,result;
  26.  
  27. printf("Podaj liczbe: ");
  28. scanf("%d",&num);
  29. printf("Podaj 1 granice: ");
  30. scanf("%d",&up);
  31. printf("Podaj 2 granice: ");
  32. scanf("%d",&down);
  33.  
  34. if(down>up)
  35. {
  36. temp=up;
  37. up=down;
  38. down=temp;
  39. }
  40.  
  41. result=clamp(num,down,up);
  42. printf("%d",result);
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement