- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 all Numbers in a Range Divisible by a Given Number
Let's assume the lower and upper limit for the range is 2 and 10, respectively, and the given number is 2.
Iterate in the range of 2 to 10 and find modulo of 2 and print them.
Steps
- Define variables for upper and lower limit for the range.
- Print statement for upper and lower limit.
- Take input from the user.
- Define a variable (n) to check the divisibility in a range.
- Take the input from users for n.
- Iterate in the range of lowerLimit and upperLimit.
- Find modulo with n in the range and print them.
Example
package main import "fmt" func main(){ var upperLimit, lowerLimit int fmt.Printf("Enter upper limit for the range: ") fmt.Scanf("%d", &lowerLimit) fmt.Printf("Enter lower limit for the range: ") fmt.Scanf("%d", &upperLimit) var n int fmt.Printf("Enter a number n: ") fmt.Scanf("%d", &n) for i:=lowerLimit; i<=upperLimit; i++{ if i%n == 0 { fmt.Println(i) } } }
Output
Enter lower limit for the range: 2 Enter upper limit for the range: 10 Enter a number n: 2 2 4 6 8 10
- Related Articles
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Print Odd Numbers Within a Given Range
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Python program to print all the numbers divisible by 3 and 5 for a given number
- Golang Program to print all integers between a range that aren't divisible by either 2 or 3
- Golang Program to Find the Numbers which are Divisible by 7 and Multiple of 5 in a Given Range
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Write a Golang program to find prime numbers in a given range
- Program to print all palindromes in a given range in C++
- Program to print all the numbers divisible by 3 and 5 in C++
- Count the numbers divisible by ‘M’ in a given range in C++
- Print all Good numbers in given range in C++
- Program to print prime numbers in a given range using C++ STL
- Golang Program to Print the Numbers in a Range (1, upper) without Using any Loops

Advertisements