{"id":14706,"date":"2024-05-28T13:27:14","date_gmt":"2024-05-28T10:27:14","guid":{"rendered":"https:\/\/elzero.org\/?p=14706"},"modified":"2024-05-28T13:27:14","modified_gmt":"2024-05-28T10:27:14","slug":"implement-functions-with-cpp-round-floor-ceil","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/implement-functions-with-cpp-round-floor-ceil\/","title":{"rendered":"Round, Floor, Ceil"},"content":{"rendered":"<h3>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-c\">\r\n#include <iostream>\r\n#include <cmath>\r\nusing namespace std;\r\n\r\n\/*\r\n  Round\r\n  Floor\r\n  Ceil\r\n*\/\r\n\r\nint imp_round(double num)\r\n{\r\n  return num + 0.5;\r\n}\r\n\r\nint imp_floor(double num)\r\n{\r\n  return num;\r\n}\r\n\r\nint imp_ceil(double num)\r\n{\r\n  int inum = num;  \/\/ 3\r\n  if (num == inum) \/\/ 3.1 == 3\r\n    return inum;\r\n  return num + 1;\r\n}\r\n\r\nint main()\r\n{\r\n  cout << imp_round(3.5) << endl;  \/\/ 4\r\n  cout << imp_round(3.9) << endl;  \/\/ 4\r\n  cout << imp_round(3.4) << endl;  \/\/ 3\r\n  cout << imp_round(3.49) << endl; \/\/ 3\r\n\r\n  cout << imp_floor(3.9) << endl; \/\/ 3\r\n  cout << imp_floor(3.5) << endl; \/\/ 3\r\n  cout << imp_floor(3.1) << endl; \/\/ 3\r\n\r\n  cout << imp_ceil(3.9) << endl; \/\/ 4\r\n  cout << imp_ceil(3.5) << endl; \/\/ 4\r\n  cout << imp_ceil(3.1) << endl; \/\/ 4\r\n  cout << imp_ceil(3) << endl;   \/\/ 3\r\n  cout << imp_ceil(3.0) << endl; \/\/ 3\r\n  cout << imp_ceil(3.1) << endl; \/\/ 4\r\n  return 0;\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1454],"tags":[],"class_list":["post-14706","post","type-post","status-publish","format-standard","hentry","category-implement-functions-with-cpp"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14706"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14706\/revisions"}],"predecessor-version":[{"id":14707,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14706\/revisions\/14707"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}