- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to Print Odd Numbers Within a Given Range
To print odd number in a range, we can take two inputs, a and b, for lower and upper limits.
Example
a = 2 and b = 9
Numbers between a and b are: 2, 3, 4, 5, 6, 7, 8, 9
Odd numbers are: 3, 5, 7, 9
Steps
- Define two numbers, a and b.
- Take user inputs for the numbers, a and b.
- Iterate the number between a and b.
- Find the modulo of 2, print the number if modulo of 2 of that number is not zero.
Example
package main import "fmt" func main(){ var a, b int fmt.Print("Enter lower limit number: ") fmt.Scanf("%d", &a) fmt.Print("Enter higher limit number: ") fmt.Scanf("%d", &b) for i := a; i<=b; i++{ if i%2!=0 { fmt.Println(i) } } }
Output
Enter lower limit number: 2 Enter higher limit number: 9 3 5 7 9
- Related Articles
- PHP program to find the sum of odd numbers within a given range
- Python program to print all odd numbers in a range
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- How to print array elements within a given range using Numpy?
- C++ program to find numbers with K odd divisors in a given range
- Write a Golang program to find prime numbers in a given range
- Program to print prime numbers in a given range using C++ STL
- Python program to generate random numbers within a given range and store in a list?
- Java program to generate random numbers within a given range and store in a list
- How to find Kaprekar numbers within a given range using Python?
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Python program to print odd numbers in a list
- Golang Program to Print the Numbers in a Range (1, upper) without Using any Loops
- Java Program to create random BigInteger within a given range
- Python - Find the number of prime numbers within a given range of numbers

Advertisements