
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Numbers Divisible by 7 and Multiple of 5 in Go
Steps
- Take in the upper and lower range and store them in separate variables.
- Use a for loop which ranges from the lower range to the upper range.
- Find the numbers which are divisible by both 5 and 7.
- Print those numbers.
Case 1 Enter the lower range: 1 Enter the upper range: 100 35 70 |
Case 2 Enter the lower range: 400 Enter the upper range: 700 420 455 490 525 560 595 630 665 700 |
Explanation
- User must enter the upper range limit and the lower range limit.
- The for loop ranges from the lower limit to the upper limit.
- The value of i ranges from the lower limit to the upper limit.
- Whenever the remainder of i divided by 5 and 7 is equal to 0, print i.
Example
package main import "fmt" func main(){ var upperLimit, lowerLimit int fmt.Printf("Enter lower limit for the range: ") fmt.Scanf("%d", &lowerLimit) fmt.Printf("Enter upper limit for the range: ") fmt.Scanf("%d", &upperLimit) for i:=lowerLimit; i<=upperLimit; i++{ if i%7 == 0 && i%5 == 0{ fmt.Println(i) } } }
Output
Enter lower limit for the range: 1 Enter upper limit for the range: 100 35 70
Advertisements