Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. /* function prints "hello" */
  4. /*declaration */
  5. void print_hello();
  6. /* function prints current year */
  7. void print_current_year();
  8. /* function prints the specific year */
  9. void print_this_year(int y);
  10. /* function tells, if value 1 can be divided by value 2 */
  11. void can_that_be_divided(int v1, int v2);
  12. /* function rounds a decimal value with given decimals, value is printed then */
  13. void round_up_this(double value, int decimals);
  14. /* function rounds a decimal value with given decimals and returns the result */
  15. double round_up_this_and_return(double value, int decimals);
  16.  
  17. int main()
  18. {
  19. /* call */
  20. print_hello();
  21. print_current_year();
  22. print_this_year(2020);
  23. can_that_be_divided(6,3);
  24. round_up_this(23.45555 ,2);
  25. double result = round_up_this_and_return(1234.6666,2);
  26. printf("result is %lf \n",result);
  27. printf("result is now %lf \n", round_up_this_and_return(8.8888,3));
  28. double x = 345.678;
  29. int d = 3;
  30. print("result is now %lf \n",round_up_this_and_return(x,d));
  31. return 0;
  32. }
  33.  
  34. double round_up_this_and_return(double value, int decimals)
  35. {
  36. int p = 1;
  37. int k;
  38. for (k = 0; k < decimals; k++);
  39. p = p * 10;
  40. value = (int)(value * p + 0.5)/(1.0*p);
  41. return value;
  42.  
  43.  
  44.  
  45. }
  46.  
  47.  
  48. void round_up_this(double value, int decimals)
  49. {
  50. int p = 1;
  51. int k;
  52. for (k = 0; k < decimals; k++);
  53. p = p * 10;
  54.  
  55. printf("%d \n",p);
  56. value = (int)(value * p + 0.5)/(1.0*p); /* 23.444 => 2344.4 + 0.5 => 2344.9 */
  57. printf("result is %lf \n",value);
  58. /* 23.45555 => 2345.55 => 2346.15 => 2346 => 23.46 */
  59. }
  60.  
  61. void can_that_be_divided(int v1, int v2)
  62. {
  63. if (v1%v2 == 0)
  64. printf("yeah \n");
  65. else
  66. printf("nope \n");
  67. }
  68.  
  69. void print_this_year(int y)
  70. {
  71. printf("%d \n", y);
  72. }
  73.  
  74.  
  75. void print_current_year()
  76. {
  77. printf("2017 \n");
  78. }
  79.  
  80.  
  81. /* definition, implementation */
  82. void print_hello()
  83. {
  84. printf("hello \n");
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement