<\/span><\/h2>\n\n\n\n\/\/ Go Program to Check Whether a Number is Even or Odd\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar num int\n\n\tfmt.Print(\"Enter an integer: \")\n\tfmt.Scanln(&num)\n\n\tif num%2 == 0 {\n\t\tfmt.Println(num, \" is an even number.\")\n\t} else {\n\t\tfmt.Println(num, \"is an odd number.\")\n\t}\n}\n<\/pre>\n\n\n\nOutput<\/strong><\/p>\n\n\n\nEnter an integer: 31\r\n31 is an odd number.<\/code><\/pre>\n\n\n\n<\/span>How Does This Program Work?<\/strong><\/span><\/h2>\n\n\n\n\tvar num int\n<\/pre>\n\n\n\nWe have declared an integer data type variable named num<\/strong>.<\/p>\n\n\n\n\tfmt.Print(\"Enter an integer: \")\n\tfmt.Scanln(&num)\n<\/pre>\n\n\n\nThe user is asked to enter a positive integer to find out whether it\u2019s an even number or an odd number. The integer entered by the user is stored in num<\/strong> named variable.<\/p>\n\n\n\n\tif num%2 == 0 {\n\t\tfmt.Println(num, \" is an even number.\")\n\t} else {\n\t\tfmt.Println(num, \"is an odd number.\")\n\t}\n<\/pre>\n\n\n\nNow, we take advantage of the if…else condition to check whether the integer is an even number or an odd number.<\/p>\n\n\n\n
We use the %<\/strong> modulus operator to find the remainder when num<\/strong> is divided by 2<\/strong>. If the remainder is 0<\/strong>, then it means the integer is completely divisible by 2<\/strong>. Therefore, the integer is an even number<\/strong>.<\/p>\n\n\n\nIf the above condition is false, then it means that the integer leaves a remainder other than 0. Therefore, in such a case, the entered integer will be an odd number<\/strong>.<\/p>\n\n\n\n<\/span>Conclusion<\/strong><\/span><\/h2>\n\n\n\nIn this post, you learned how to write a program to check whether a number is even or odd using the Go programming language<\/strong>.<\/p>\n\n\n\nIf you have any doubts regarding the tutorial, leave your queries in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"
In this post, we will learn how to write a program to check whether a number is even or odd using the Go programming language.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[808],"tags":[809],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts\/8482"}],"collection":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/comments?post=8482"}],"version-history":[{"count":4,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts\/8482\/revisions"}],"predecessor-version":[{"id":8487,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts\/8482\/revisions\/8487"}],"wp:attachment":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/media?parent=8482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/categories?post=8482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/tags?post=8482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}