{"id":737,"date":"2026-10-04T13:00:00","date_gmt":"2026-10-04T07:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=737"},"modified":"2026-11-29T01:29:43","modified_gmt":"2026-11-28T19:59:43","slug":"go-basic-math-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/","title":{"rendered":"Go Math Programs with Output: Sum, Swap, Area and Interest"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go math programs turn the numbers you read from the user into real answers, such as a total bill, an area or the interest on a loan. In this post, you will write fourteen short programs with their exact output, from adding two numbers to compound interest. Then you will practice the number questions that catch many people out in interviews.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You already know how to print values from our <a href=\"https:\/\/smitabharat.com\/blog\/go-hello-world-print-programs\/\">Go print programs<\/a> and how to read them from <a href=\"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/\">Go user input programs<\/a>. Here we use fixed values, so you can run every program in the Go Playground too. All programs were tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go Math Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go math programs are programs that calculate something with numbers. They use arithmetic operators like <code>+<\/code>, <code>-<\/code>, <code>*<\/code>, <code>\/<\/code> and <code>%<\/code>, plus the <code>math<\/code> package for things like square roots and powers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of Go as a calculator that is very strict about types. An <code>int<\/code> holds whole numbers, and a <code>float64<\/code> holds decimals. Go will not mix them for you, so you must say clearly which kind of number you want.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Math Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every real app does some maths, so Go math programs are worth practising early. A shopping cart adds prices, a fitness app works out BMI, and a bank app calculates interest. Interviewers also use small math programs to check whether you understand integer division, rounding and overflow.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Billing:<\/strong> totals, tax and discounts all need careful decimal handling.<\/li>\n\n\n<li><strong>Geometry:<\/strong> areas and distances use <code>math.Pi<\/code>, <code>math.Sqrt<\/code> and <code>math.Hypot<\/code>.<\/li>\n\n\n<li><strong>Interviews:<\/strong> questions like &#8220;what is 7 \/ 2 in Go?&#8221; test your type knowledge.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Math Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">All Go math programs follow the same three steps. First, you store the input values in variables of the right type. Next, you apply operators or <code>math<\/code> functions. Finally, you print the result with the format you need.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1-1024x640.png\" alt=\"Go math programs diagram showing input values, operators and math functions, and formatted output\" class=\"wp-image-711\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Store values with the right type, calculate with operators or the math package, then print the result.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the arithmetic operators and what each one gives for 17 and 5.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operator<\/th><th>Meaning<\/th><th>17 and 5 as int<\/th><th>17.0 and 5.0 as float64<\/th><\/tr><\/thead><tbody><tr><td>+<\/td><td>Add<\/td><td>22<\/td><td>22<\/td><\/tr><tr><td>&#8211;<\/td><td>Subtract<\/td><td>12<\/td><td>12<\/td><\/tr><tr><td>*<\/td><td>Multiply<\/td><td>85<\/td><td>85<\/td><\/tr><tr><td>\/<\/td><td>Divide<\/td><td>3<\/td><td>3.4<\/td><\/tr><tr><td>%<\/td><td>Remainder<\/td><td>2<\/td><td>Not allowed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you want the theory behind each operator, read <a href=\"https:\/\/smitabharat.com\/blog\/go-operators-examples\/\">Go operators explained with examples<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Go Math Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These first Go math programs use only the five arithmetic operators.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Add Two Numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the easiest program in the post. It stores two numbers, adds them and prints the answer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\" \/\/ fmt is the package for printing\n\nfunc main() {\n    \/\/ Step 1: store the two numbers\n    \/\/ := creates a new variable and gives it a value\n    firstNumber := 25\n    secondNumber := 17\n\n    \/\/ Step 2: add them and keep the answer in a new variable\n    sum := firstNumber + secondNumber\n\n    \/\/ Step 3: print the answer\n    fmt.Println(\"First number:\", firstNumber)\n    fmt.Println(\"Second number:\", secondNumber)\n    fmt.Println(\"Sum:\", sum)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>First number: 25\nSecond number: 17\nSum: 42<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>:=<\/code> sign creates a variable and sets its value in one go. Go sees whole numbers, so it makes both variables <code>int<\/code>. Then <code>+<\/code> adds them, and <code>fmt.Println<\/code> prints each label with its value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Arithmetic on Two Numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program shows all five operators on two whole numbers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ Two whole numbers (Go makes them int)\n    first := 17\n    second := 5\n\n    fmt.Println(\"Sum:\", first+second)\n    fmt.Println(\"Difference:\", first-second)\n    fmt.Println(\"Product:\", first*second)\n    fmt.Println(\"Quotient:\", first\/second)  \/\/ int division drops the decimal part\n    fmt.Println(\"Remainder:\", first%second) \/\/ % gives what is left over\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Sum: 22\nDifference: 12\nProduct: 85\nQuotient: 3\nRemainder: 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each line does one operation and prints it straight away. Because both numbers are ints, <code>17 \/ 5<\/code> gives 3, not 3.4. The <code>%<\/code> operator gives the part left over, which is 2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Swap Two Numbers Three Ways<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Swapping is a classic interview task. Go makes it very short with multiple assignment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ Way 1: Go multiple assignment\n    first, second := 10, 20\n    first, second = second, first \/\/ Go reads both right side values first, then assigns\n    fmt.Println(\"Way 1:\", first, second)\n\n    \/\/ Way 2: use a temporary variable to hold one value\n    left, right := 10, 20\n    temp := left \/\/ remember the old left value\n    left = right\n    right = temp\n    fmt.Println(\"Way 2:\", left, right)\n\n    \/\/ Way 3: without a third variable, using + and -\n    top, bottom := 10, 20\n    top = top + bottom    \/\/ top is now 30\n    bottom = top - bottom \/\/ bottom is now 10\n    top = top - bottom    \/\/ top is now 20\n    fmt.Println(\"Way 3:\", top, bottom)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Way 1: 20 10\nWay 2: 20 10\nWay 3: 20 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>first, second = second, first<\/code> works because Go reads both values on the right before it assigns them. Way 2 parks one value in <code>temp<\/code>, so nothing is lost. Way 3 uses a sum to swap, which interviewers like to ask about. The first way is the normal way to swap in Go.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Average of Five Numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To get a decimal average, convert the total to <code>float64<\/code> before you divide.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ A slice is a list of values of the same type\n    marks := []int{78, 85, 92, 66, 81}\n\n    \/\/ Step 1: add up all the marks\n    total := 0\n    for _, mark := range marks { \/\/ range gives each item; _ skips the position\n        total += mark \/\/ same as total = total + mark\n    }\n\n    \/\/ Step 2: convert to float64 so the decimal part is kept\n    average := float64(total) \/ float64(len(marks)) \/\/ len gives the number of items\n\n    \/\/ Step 3: print the results\n    fmt.Println(\"Total:\", total)\n    fmt.Printf(\"Average: %.2f\\n\", average) \/\/ %.2f prints 2 decimal places, \\n is a new line\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Total: 402\nAverage: 80.40<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop visits each mark and adds it to <code>total<\/code>. Then the program converts both numbers to <code>float64<\/code> and divides. If we wrote <code>total \/ len(marks)<\/code>, Go would give 80, because both are ints.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Math Programs with Formulas<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s write Go math programs with real formulas from school maths and finance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Area and Perimeter of a Rectangle and Circle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>math<\/code> package gives you <code>math.Pi<\/code>, so you do not have to type 3.14159 yourself.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\" \/\/ math has Pi, Sqrt, Pow and many more\n)\n\nfunc main() {\n    \/\/ Rectangle sizes with decimals (Go makes them float64)\n    length := 12.5\n    width := 4.0\n\n    rectangleArea := length * width\n    rectanglePerimeter := 2 * (length + width)\n    fmt.Printf(\"Rectangle area: %.2f\\n\", rectangleArea)\n    fmt.Printf(\"Rectangle perimeter: %.2f\\n\", rectanglePerimeter)\n\n    \/\/ Circle size\n    radius := 7.0\n    circleArea := math.Pi * radius * radius\n    circumference := 2 * math.Pi * radius\n    fmt.Printf(\"Circle area: %.2f\\n\", circleArea)\n    fmt.Printf(\"Circle circumference: %.2f\\n\", circumference)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Rectangle area: 50.00\nRectangle perimeter: 33.00\nCircle area: 153.94\nCircle circumference: 43.98<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each formula gets its own named variable, so you can read it like school maths. We stored the sizes as <code>float64<\/code>, so the results keep their decimals. Then <code>%.2f<\/code> rounds the output to two places.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Simple Interest<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Simple interest uses the formula P x R x T \/ 100.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    principal := 50000.0 \/\/ the loan amount\n    rate := 7.5          \/\/ percent per year\n    years := 3.0\n\n    \/\/ Formula: principal x rate x years \/ 100\n    interest := principal * rate * years \/ 100\n    totalAmount := principal + interest\n\n    fmt.Printf(\"Interest: %.2f\\n\", interest)\n    fmt.Printf(\"Total amount: %.2f\\n\", totalAmount)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Interest: 11250.00\nTotal amount: 61250.00<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program multiplies the three values and divides by 100 to get the interest. Next, it adds the interest to the loan to get the total. We wrote <code>50000.0<\/code> with a decimal point, so all values are <code>float64<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Compound Interest with math.Pow<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Compound interest grows on itself, so we need a power. <code>math.Pow(x, y)<\/code> gives x to the power y.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    principal := 50000.0\n    rate := 7.5 \/\/ percent per year\n    years := 3.0\n\n    \/\/ Step 1: growth for one year, for example 1.075\n    yearlyGrowth := 1 + rate\/100\n\n    \/\/ Step 2: apply that growth once per year\n    amount := principal * math.Pow(yearlyGrowth, years)\n\n    \/\/ Step 3: the interest is the extra money on top of the loan\n    compoundInterest := amount - principal\n\n    fmt.Printf(\"Amount: %.2f\\n\", amount)\n    fmt.Printf(\"Compound interest: %.2f\\n\", compoundInterest)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Amount: 62114.84\nCompound interest: 12114.84<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the program works out how much the money grows in one year. Then <code>math.Pow<\/code> repeats that growth for 3 years. Compare this with Program 6. The same loan costs about 865 more with yearly compounding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Celsius to Fahrenheit<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The formula is F = C x 9 \/ 5 + 32. Here we convert four temperatures in a loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    celsiusValues := []float64{-10, 0, 37, 100}\n\n    for _, celsius := range celsiusValues {\n        fahrenheit := celsius*9\/5 + 32\n        \/\/ %6.1f means: use 6 characters wide, with 1 decimal place\n        fmt.Printf(\"%6.1f C = %6.1f F\\n\", celsius, fahrenheit)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> -10.0 C =   14.0 F\n   0.0 C =   32.0 F\n  37.0 C =   98.6 F\n 100.0 C =  212.0 F<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop takes one Celsius value at a time. It applies the formula and prints both values side by side. The width 6 in <code>%6.1f<\/code> lines the numbers up in neat columns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: BMI Calculator<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">BMI is weight in kg divided by height in metres squared.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    weight := 68.0 \/\/ kg\n    height := 1.72 \/\/ metres\n\n    \/\/ Formula: weight \/ (height x height)\n    bmi := weight \/ (height * height)\n    fmt.Printf(\"BMI: %.1f\\n\", bmi) \/\/ %.1f prints 1 decimal place\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>BMI: 23.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The brackets make Go square the height first. Then the weight is divided by that value. Finally, <code>%.1f<\/code> shows the BMI with one decimal place.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Shopping Bill with Discount and Tax<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This everyday example works out a final bill. It applies a discount first and then adds tax.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    price := 1200.0 \/\/ price of one item in rupees\n    quantity := 3.0 \/\/ number of items\n    discountPercent := 10.0\n    taxPercent := 18.0\n\n    \/\/ Step 1: cost before discount\n    subtotal := price * quantity\n\n    \/\/ Step 2: take away the discount\n    discount := subtotal * discountPercent \/ 100\n    afterDiscount := subtotal - discount\n\n    \/\/ Step 3: add tax on the discounted amount\n    tax := afterDiscount * taxPercent \/ 100\n    finalBill := afterDiscount + tax\n\n    fmt.Printf(\"Subtotal: %.2f\\n\", subtotal)\n    fmt.Printf(\"Discount: %.2f\\n\", discount)\n    fmt.Printf(\"Tax: %.2f\\n\", tax)\n    fmt.Printf(\"Final bill: %.2f\\n\", finalBill)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Subtotal: 3600.00\nDiscount: 360.00\nTax: 583.20\nFinal bill: 3823.20<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program builds the bill in small steps, just like a shop does. First it multiplies price by quantity. Next it removes 10 percent and then adds 18 percent tax on what is left.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Math Programs with the math Package<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>math<\/code> package has ready-made functions for most needs. These programs show the ones you will use most.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Square Root, Cube Root and Power<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    fmt.Println(\"Square root of 144:\", math.Sqrt(144))\n    fmt.Println(\"Cube root of 27:\", math.Cbrt(27))\n    fmt.Println(\"2 to the power 10:\", math.Pow(2, 10))\n    fmt.Println(\"Absolute of -8.5:\", math.Abs(-8.5)) \/\/ Abs removes the minus sign\n    fmt.Println(\"Max of 3 and 9:\", max(3, 9))        \/\/ max is built into Go, no import needed\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Square root of 144: 12\nCube root of 27: 3\n2 to the power 10: 1024\nAbsolute of -8.5: 8.5\nMax of 3 and 9: 9<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each line calls one function and prints its answer. <code>max<\/code> and <code>min<\/code> are built into Go since version 1.21, so they work on ints without the <code>math<\/code> package. The <code>math<\/code> functions use <code>float64<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Rounding Numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Go has four rounding functions. Each one treats the decimal part differently.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    values := []float64{2.5, 2.4, -2.5}\n\n    for _, value := range values {\n        rounded := math.Round(value)   \/\/ nearest whole number\n        floor := math.Floor(value)     \/\/ always goes down\n        ceiling := math.Ceil(value)    \/\/ always goes up\n        truncated := math.Trunc(value) \/\/ cuts off the decimals\n        fmt.Println(value, \"Round:\", rounded, \"Floor:\", floor,\n            \"Ceil:\", ceiling, \"Trunc:\", truncated)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2.5 Round: 3 Floor: 2 Ceil: 3 Trunc: 2\n2.4 Round: 2 Floor: 2 Ceil: 3 Trunc: 2\n-2.5 Round: -3 Floor: -3 Ceil: -2 Trunc: -2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop tries all four functions on each value. <code>Round<\/code> goes to the nearest whole number and moves halves away from zero. <code>Floor<\/code> always goes down, <code>Ceil<\/code> always goes up, and <code>Trunc<\/code> just cuts off the decimals.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: Distance Between Two Points<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>math.Hypot<\/code> finds the length of the long side of a right triangle, which is the distance between two points.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    \/\/ Point A is (1, 2) and point B is (4, 6)\n    startX, startY := 1.0, 2.0\n    endX, endY := 4.0, 6.0\n\n    \/\/ Step 1: how far apart the points are on each axis\n    across := endX - startX \/\/ 3\n    up := endY - startY     \/\/ 4\n\n    \/\/ Step 2: Hypot gives the square root of (across x across + up x up)\n    distance := math.Hypot(across, up)\n    fmt.Println(\"Distance:\", distance)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Distance: 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the program finds the gap on the x axis and the y axis. These two gaps are the short sides of a triangle. Then <code>math.Hypot<\/code> gives the long side, which is 5.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: Integer Limits and Overflow<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Every int type has a limit. If you go past it at run time, the value wraps around without any error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    \/\/ int8 can only hold values from -128 to 127\n    var small int8 = 127\n    small++ \/\/ add 1, which goes past the limit\n    fmt.Println(\"int8 after 127 + 1:\", small)\n\n    \/\/ The math package has the limits as constants\n    fmt.Println(\"Max int64:\", math.MaxInt64)\n    fmt.Println(\"Max uint8:\", math.MaxUint8)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>int8 after 127 + 1: -128\nMax int64: 9223372036854775807\nMax uint8: 255<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">An <code>int8<\/code> holds -128 to 127, so 127 + 1 wraps to -128. The <code>math<\/code> package stores each limit as a ready constant. Choose a type that is big enough for your data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">int vs float64 in Go Math Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Picking the right number type is the most important choice in Go math programs. The diagram and table below compare the two most common types.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2-1024x640.png\" alt=\"Go math programs comparison of int and float64 types\" class=\"wp-image-712\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Use int for counts and whole numbers, and float64 for measurements and decimal results.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>int<\/th><th>float64<\/th><\/tr><\/thead><tbody><tr><td>Holds<\/td><td>Whole numbers<\/td><td>Numbers with decimals<\/td><\/tr><tr><td>7 \/ 2 gives<\/td><td>3<\/td><td>3.5<\/td><\/tr><tr><td>% operator<\/td><td>Allowed<\/td><td>Not allowed, use math.Mod<\/td><\/tr><tr><td>Exact results<\/td><td>Yes, within range<\/td><td>Small rounding errors<\/td><\/tr><tr><td>Divide by zero<\/td><td>Panic at run time<\/td><td>Gives +Inf<\/td><\/tr><tr><td>Good for<\/td><td>Counts, IDs, loops<\/td><td>Prices, sizes, science<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For money, many teams store paise or cents as an <code>int<\/code> to avoid rounding errors. Use <code>float64<\/code> for measurements and science.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Math Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Integer division by accident:<\/strong> <code>7 \/ 2<\/code> is 3. Convert to <code>float64<\/code> when you need decimals.<\/li>\n\n\n<li><strong>Mixing types:<\/strong> <code>count + price<\/code> with an int and a float64 does not compile. Convert one of them first.<\/li>\n\n\n<li><strong>Trusting float equality:<\/strong> <code>0.1 + 0.2 == 0.3<\/code> is false. Compare with a small tolerance instead.<\/li>\n\n\n<li><strong>Ignoring overflow:<\/strong> small int types wrap around silently, so pick <code>int<\/code> or <code>int64<\/code> for big values.<\/li>\n\n\n<li><strong>Dividing by a zero variable:<\/strong> an int divided by zero panics, so check the divisor first.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Math Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pick the type first<\/strong>, because it decides how every operator behaves.<\/li>\n\n\n<li><strong>Use math.Pi and math functions<\/strong> instead of typing magic numbers.<\/li>\n\n\n<li><strong>Format output with %.2f<\/strong>, so users see clean results.<\/li>\n\n\n<li><strong>Store money as whole paise or cents<\/strong>, to avoid float rounding errors.<\/li>\n\n\n<li><strong>Check divisors before dividing<\/strong>, so the program never crashes.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go Math Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go math programs come up often in coding rounds. Each answer has a complete program and its real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Division Questions in Go Math Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ Line 1: int division, then float division\n    fmt.Println(7\/2, 7.0\/2, 7\/2.0)\n    \/\/ Line 2: division and remainder with negative numbers\n    fmt.Println(-7\/2, -7%3, 7%-3)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3 3.5 3.5\n-3 -1 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If both numbers are ints, Go does int division. If either one has a decimal point, you get a float answer. Int division cuts toward zero, so -7 \/ 2 is -3. The remainder takes the sign of the first number, so -7 % 3 is -1 and 7 % -3 is 1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What happens when you divide an int by zero?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    total := 10\n    divisor := 0\n    fmt.Println(total \/ divisor) \/\/ crashes while the program runs\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>panic: runtime error: integer divide by zero<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program crashes with a panic, followed by a stack trace. If you write <code>10 \/ 0<\/code> with constants, Go refuses to compile it and reports &#8220;division by zero&#8221; instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What happens when you divide a float by zero?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    zero := 0.0 \/\/ a float64 zero\n    fmt.Println(1\/zero, -1\/zero, zero\/zero)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>+Inf -Inf NaN<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Floats follow the IEEE 754 standard, so there is no panic. You get positive infinity, negative infinity or NaN, which means &#8220;not a number&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. How do you get the remainder of two floats?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>%<\/code> operator only works on integers. For floats, use <code>math.Mod(7.5, 2)<\/code>, which returns 1.5.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Type Questions in Go Math Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. Why does this program not compile?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    count := 3   \/\/ int\n    price := 2.5 \/\/ float64\n    fmt.Println(count * price)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>invalid operation: count * price (mismatched types int and float64)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go never converts number types for you. Write <code>float64(count) * price<\/code> to make both sides the same type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    price := 9.99\n    fmt.Println(int(price), int(-price)) \/\/ int(...) converts a float to an int\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>9 -9<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Converting a float to an int drops the decimal part. It does not round, so 9.99 becomes 9.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ Constants: Go does exact maths while compiling\n    fmt.Println(0.1+0.2 == 0.3)\n\n    \/\/ Variables: real float64 values with tiny rounding errors\n    first := 0.1\n    second := 0.2\n    fmt.Println(first+second == 0.3)\n    fmt.Println(first + second)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true\nfalse\n0.30000000000000004<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a great trick question. With constants, Go does exact maths at compile time, so the first line is true. With <code>float64<\/code> variables, the tiny binary rounding error appears, so the second line is false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. Why does this not compile?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    var value byte = 256 \/\/ a byte can only hold 0 to 255\n    fmt.Println(value)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cannot use 256 (untyped int constant) as byte value in variable declaration (overflows)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>byte<\/code> holds 0 to 255. Go checks constants at compile time, so it catches this overflow before the program runs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    var counter uint8 = 0 \/\/ uint8 holds 0 to 255, never negative\n    counter--             \/\/ subtract 1\n    fmt.Println(counter)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>255<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Unsigned types cannot be negative. So 0 minus 1 wraps around to the largest value, 255.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Operator Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. Can you write fmt.Println(count++) in Go?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    count := 5\n    fmt.Println(count++)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>syntax error: unexpected ++ in argument list; possibly missing comma or )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No. In Go, <code>count++<\/code> is a statement, not an expression, so it cannot sit inside another call. Also, Go has no <code>++count<\/code> form at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ &amp; is AND, | is OR, ^ is XOR, &lt;&lt; and &gt;&gt; shift the bits\n    fmt.Println(5&amp;3, 5|3, 5^3, 1&lt;&lt;3, 16&gt;&gt;2)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 7 6 8 4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are bitwise operators. <code>&amp;<\/code> is AND, <code>|<\/code> is OR, <code>^<\/code> is XOR, and the shifts move bits left or right. <code>1 &lt;&lt; 3<\/code> is the same as 1 times 2 three times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    score := 10\n    score += 5 \/\/ score = score + 5\n    score *= 2 \/\/ score = score * 2\n    score -= 4 \/\/ score = score - 4\n    score \/= 3 \/\/ score = score \/ 3 (int division)\n    score %= 5 \/\/ score = score % 5\n    fmt.Println(score)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step by step, score becomes 15, 30, 26, 8 and finally 3. Work through each line slowly, because interviewers like these chains.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(2+3*4, (2+3)*4, 10-4-3, 2*3%4)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>14 20 3 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>*<\/code> and <code>%<\/code> come before <code>+<\/code> and <code>-<\/code>. Operators with the same priority run from left to right, so <code>2*3%4<\/code> is <code>6 % 4<\/code>, which is 2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">math Package Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    root := math.Sqrt(-1) \/\/ square root of a negative number\n    fmt.Println(root, math.IsNaN(root))\n\n    nan := math.NaN() \/\/ NaN means \"not a number\"\n    fmt.Println(nan == nan)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>NaN true\nfalse<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The square root of a negative number is NaN. NaN is never equal to anything, not even itself, so use <code>math.IsNaN<\/code> to test for it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ %.0f prints with no decimal places\n    fmt.Printf(\"%.0f %.0f %.0f\\n\", 0.5, 1.5, 2.5)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0 2 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Printf<\/code> rounds a half to the nearest even digit. So 0.5 becomes 0 and 2.5 becomes 2. If you need halves to round up, use <code>math.Round<\/code> before printing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16. How do you find the maximum of many numbers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since Go 1.21, the built-in <code>max<\/code> takes any number of values, such as <code>max(4, 9, 2)<\/code>. For a slice, use <code>slices.Max(numbers)<\/code> from the <code>slices<\/code> package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\"\n)\n\nfunc main() {\n    number := 2.0\n    fmt.Println(math.Pow(number, 0.5), math.Sqrt(number))\n    fmt.Printf(\"%.4f\\n\", math.Sqrt(number)) \/\/ keep 4 decimal places\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1.4142135623730951 1.4142135623730951\n1.4142<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A power of 0.5 is the same as a square root. <code>Println<\/code> shows all the digits, while <code>%.4f<\/code> keeps four decimal places.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18. How do you check if a number is even?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the remainder: <code>number%2 == 0<\/code> means even. We use this a lot in the next post on if\/else programs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This task uses ideas from several Go math programs above. Write a program that splits a restaurant bill of 2,450 rupees between 4 friends, adds a 10% tip, and prints each share with two decimal places. Hint: convert to <code>float64<\/code> before you divide.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/math\">math package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Arithmetic_operators\">Go spec: arithmetic operators<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Numeric_types\">Go spec: numeric types<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go math programs use <code>+<\/code>, <code>-<\/code>, <code>*<\/code>, <code>\/<\/code> and <code>%<\/code>, plus the <code>math<\/code> package.<\/li>\n\n\n<li>Int division drops the decimal part, so convert to <code>float64<\/code> for exact averages.<\/li>\n\n\n<li>Go never mixes number types, so you must convert them yourself.<\/li>\n\n\n<li>Small int types wrap around on overflow, and floats can have tiny rounding errors.<\/li>\n\n\n<li><code>math.Round<\/code>, <code>Floor<\/code>, <code>Ceil<\/code> and <code>Trunc<\/code> each round in a different way.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, your programs start making decisions. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/\">Go if else programs with output<\/a>. To revise the theory of numbers first, see <a href=\"https:\/\/smitabharat.com\/blog\/go-variables-constants-data-types\/\">Go variables, constants and data types<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go math programs turn the numbers you read from the user into real answers, such as a total bill, an area or the interest&hellip;<\/p>\n","protected":false},"author":1,"featured_media":713,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,95,11,109,104],"swapz_series":[],"class_list":["post-737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-math","tag-go-programs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Math Programs: Sum, Swap, Area and Interest<\/title>\n<meta name=\"description\" content=\"Go math programs with output: arithmetic, swap, area, interest, rounding and overflow, plus number interview questions with real answers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Math Programs: Sum, Swap, Area and Interest\" \/>\n<meta property=\"og:description\" content=\"Go math programs with output: arithmetic, swap, area, interest, rounding and overflow, plus number interview questions with real answers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-04T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Math Programs with Output: Sum, Swap, Area and Interest\",\"datePublished\":\"2026-10-04T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/\"},\"wordCount\":2059,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-basic-math-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Math\",\"Go Programs\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/\",\"name\":\"Go Math Programs: Sum, Swap, Area and Interest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-basic-math-programs-featured.png\",\"datePublished\":\"2026-10-04T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:43+00:00\",\"description\":\"Go math programs with output: arithmetic, swap, area, interest, rounding and overflow, plus number interview questions with real answers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-basic-math-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-basic-math-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Math Programs featured image: output of sum, area and interest programs\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-basic-math-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Math Programs with Output: Sum, Swap, Area and Interest\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Math Programs: Sum, Swap, Area and Interest","description":"Go math programs with output: arithmetic, swap, area, interest, rounding and overflow, plus number interview questions with real answers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go Math Programs: Sum, Swap, Area and Interest","og_description":"Go math programs with output: arithmetic, swap, area, interest, rounding and overflow, plus number interview questions with real answers.","og_url":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-04T07:30:00+00:00","article_modified_time":"2026-11-28T19:59:43+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Math Programs with Output: Sum, Swap, Area and Interest","datePublished":"2026-10-04T07:30:00+00:00","dateModified":"2026-11-28T19:59:43+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/"},"wordCount":2059,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Math","Go Programs"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/","name":"Go Math Programs: Sum, Swap, Area and Interest","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-featured.png","datePublished":"2026-10-04T07:30:00+00:00","dateModified":"2026-11-28T19:59:43+00:00","description":"Go math programs with output: arithmetic, swap, area, interest, rounding and overflow, plus number interview questions with real answers.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-basic-math-programs-featured.png","width":2400,"height":1260,"caption":"Go Math Programs featured image: output of sum, area and interest programs"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Math Programs with Output: Sum, Swap, Area and Interest"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=737"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/737\/revisions"}],"predecessor-version":[{"id":871,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/737\/revisions\/871"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/713"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=737"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}