Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Go Program for Reverse Natural Numbers

by suresh

This Go program to print natural numbers in reverse order uses the for loop to start traverse from n until 1. Within the loop, the println statement prints natural numbers.

package main

import "fmt"

func main() {

    var num, i int

    fmt.Print("\nEnter the Last Natural Number = ")
    fmt.Scanln(&num)

    fmt.Println("\nNatural Numbers from ", num, " to 1 are = ")
    for i = num; i >= 1; i = i - 1 {
        fmt.Print(i, "\t")
    }
    fmt.Println()
}
Go Program for Reverse Natural Numbers 1

Golang Program to Print Natural Numbers in Reverse

In this Golang program, we alter the for loop.

package main

import "fmt"

func main() {

    var num int

    fmt.Print("\nEnter the Last Natural Number = ")
    fmt.Scanln(&num)

    fmt.Println("\nNatural Numbers from ", num, " to 1 are = ")
    for num >= 1 {
        fmt.Print(num, "\t")
        num = num - 1
    }
    fmt.Println()
}
Go Program for Reverse Natural Numbers 2

This Go program accepts the minimum and maximum values and prints the natural numbers from maximum to minimum limit.

package main

import "fmt"

func main() {

    var minnum, maxnum int

    fmt.Print("\nEnter the First Natural Number = ")
    fmt.Scanln(&minnum)

    fmt.Print("\nEnter the Last Natural Number = ")
    fmt.Scanln(&maxnum)

    fmt.Println("\nNatural Numbers from ", minnum, " to ", maxnum, " are = ")
    for maxnum >= minnum {
        fmt.Print(maxnum, "\t")
        maxnum = maxnum - 1
    }
    fmt.Println()
}
Golang Program to print Natural Numbers in reverse 3

Placed Under: Go Examples

  • Golang Hello World Program
  • Go Add Two Number
  • Go Compound Interest
  • Go Count Digits in a Number
  • Go Cube of a Number
  • Go Even or Odd
  • Go Largest of Three Numbers
  • Go Reverse Natural Numbers
  • Go Multiplication Table
  • Go Number divisible by 5 and 11
  • Go Positive or Negative
  • Go Power of a Number
  • Go Print Natural Numbers
  • Go Profit or Loss
  • Go Print 1 to 100 without loop
  • Go Program to Print 1 to 100
  • Go Product of Digits in a Number
  • Go Palindrome Number Program
  • Go Print Even Numbers
  • Go Print Odd Numbers
  • Go Factors of a Number
  • Go Perfect Number
  • Go Prime Number
  • Go Reverse a Number
  • Go Simple Interest
  • Go Square of a Number
  • Go Square root of a Number
  • Go Sum of Digits in a Number
  • Go Sum & Avg of Natural Nums
  • Go Sum of Even Numbers
  • Go Sum of Odd Numbers
  • Go Sum of Even and Odd
  • Go Sphere Vol & Surface Area
  • Go Cylinder Vol & Surface Area
  • Go Cuboid Vol & Surface Area
  • Go Cube Volume & Surface Area
  • Go Cone Volume & Surface Area

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy