Read Two Numbers and Print Their Quotient and Remainder in Go

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 06:06:15

348 Views

To print the Quotient and Remainder of two numbers, we can use the division operator and the modulo operator.Let's take an Example:a = 15 and b = 2Quotient is 15/2 = 7Remainder is 15 % 2 = 1StepsDefine the variables, a and b.Use print statement for the first number.Use print statement for the second number.Find the division of the numbers, a and b.Find the remainder of the numbers, a and b.Print the calculated division.Print the calculated remainder.Example Live Demopackage main import "fmt" func main(){    var a, b int    fmt.Print("Enter first number: ")    fmt.Scanf("%d", &a)    fmt.Print("Enter second number: ... Read More

Print All Numbers in a Range Divisible by a Given Number in Go

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 06:03:22

479 Views

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.StepsDefine 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 Live Demopackage main import "fmt" func main(){    var upperLimit, lowerLimit int    fmt.Printf("Enter ... Read More

Golang Combinations Generator

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 05:36:35

561 Views

Numbers are: a, b and c => 1, 2, 3Combination of (a, b, c) are: (1, 1, 1), (1, 2, 1), (1, 2, 2), (1, 2, 3), . . ., (3, 3, 3).StepsDefine the variables, a, b and c.Print statement for the first number and scan the number.Print statement for the second number and scan the number.Print statement for the third number and scan the number.Initialize an array with numbers, a, b and c.Iterate the array with iterator i, j and k.Print (i, j, k)th index number of the array.Example Live Demopackage main import "fmt" func main(){    var a, b, ... Read More

Deep Sleep in Arduino

Yash Sanghvi
Updated on 02-Aug-2021 05:28:49

8K+ Views

The equivalent of deep sleep in Arduino would be the Power Down mode, which consumes the least power out of all the sleep modes. While this has already been covered in another article, but for the sake of completeness, here’s a brief on the sleep modes in Arduino.Arduino’s microcontroller, ATmega328P has 6 sleep modes, of which 5 are available with the avr/sleep.h library.Idle modeADC Noise ReductionPower-downPower-saveStandbyExtended StandbyEach mode has different wake-up modes and different power consumption.The Idle mode is easiest to wake up from and the Standby and Power down mode is the most difficult to wake up from (you ... Read More

Check If Two Numbers Are Amicable in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 16:02:41

518 Views

StepsRead two integers and store them in separate variables.Find the sum of the proper divisors of both the numbers.Check if the sum of the proper divisors is equal to the opposite numbers.If they are equal, they are amicable numbers.Print the final result.Enter number 1: 220Enter number 2: 284Amicable!Enter number 1: 349Enter number 2: 234Not Amicable!Example Live Demopackage main import "fmt" func main(){    var a, b int    fmt.Print("Enter first number: ")    fmt.Scanf("%d", &a)    fmt.Print("Enter second number: ")    fmt.Scanf("%d", &b)    sum1 := 0    for i:=1; i

Print Numbers in a Range without Using Loops in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:54:37

240 Views

StepsDefine a recursive function.Define a base case for that function that the number should be greater than zero.If the number is greater than 0, call the function again with the argument as the number minus 1.Print the number.Enter the upper limit: 512345Enter the upper limit: 1512..15Example Live Demopackage main import (    "fmt" ) func printNo(number int){    if number >= 1{       printNo(number-1)       fmt.Println(number)    } } func main(){    var upper int    fmt.Print("Enter the upper limit: ")    fmt.Scanf("%d", &upper)    printNo(upper) }OutputEnter the upper limit: 5 1 2 3 4 5

Find Gravitational Force Between Two Objects in Golang

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:53:38

442 Views

StepsRead both the masses and the distance between the masses and store them in separate variables.Initialize one of the variables to the value of gravitational constant, G.Then, the formula f=(G*m1*m2)/(r**2) is used to determine the force acting between the masses.Rounding off up to two decimal places, print the value of the force.Enter the first mass: 1000000Enter the second mass: 500000Enter the distance between the centres of the masses: 20Hence, the gravitational force is: 0.08 NEnter the first mass: 90000000Enter the second mass: 7000000Enter the distance between the centres of the masses: 20Hence, the gravitational force is: 105.1 NExplanationUser must enter ... Read More

Find Area of Triangle Given All Three Sides in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:52:40

563 Views

StepsRead all the three sides of the triangle and store them in three separate variables.Using the Heron's formula, compute the area of the triangle.Print the area of the triangle.Enter first side: 15Enter second side: 9Enter third side: 7Area of the triangle is: 20.69Enter first side: 5Enter second side: 6Enter third side: 7Area of the triangle is: 14.7ExplanationUser must enter all three numbers and store them in separate variables.First, the value of s is found which is equal to (a+b+c)/2Then, the Heron's formula is applied to determine the area of the triangle formed by all three sides.Finally, the area of the ... Read More

Check If a Number is a Perfect Number in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:49:58

591 Views

StepsRead an integer and store it in a variable.Initialize a variable to count the sum of the proper divisors to 0.Use a for loop and an if statement to add the proper divisors of the integer to the sum variable.Check if the sum of the proper divisors of the number is equal to the variable.Print the final result.Enter any number: 6The number is a Perfect number!Enter any number: 25The number is not a Perfect number!Example Live Demopackage main import "fmt" func main(){    var n int    fmt.Print("Enter any number: ")    fmt.Scanf("%d", &n)    sum1 := 0    for i:=1; ... Read More

Find Numbers Divisible by 7 and Multiple of 5 in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:48:27

542 Views

StepsTake 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 1Enter the lower range: 1Enter the upper range: 1003570Case 2Enter the lower range: 400Enter the upper range: 700420455490525560595630665700ExplanationUser 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 ... Read More

Advertisements