- 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
Advertisements