Rishikesh Kumar Rishi has Published 1162 Articles

Golang Program to Determine Recursively Whether a Given Number is Even or Odd

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 02-Aug-2021 07:09:21

277 Views

StepsTake a number from the user and store it in a variable.Pass the number as an argument to a recursive function.Define the base condition as the number to be lesser than 2.Otherwise, call the function recursively with the number minus 2.Then, return the result and check if the number is ... Read More

Golang Program to Read Two Numbers and Print their Quotient and Remainder

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 02-Aug-2021 06:06:15

277 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 ... Read More

Golang Program to Print all Numbers in a Range Divisible by a Given Number

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 02-Aug-2021 06:03:22

357 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 ... Read More

Golang Program to Read Three Digits and Print all Possible Combinations from the Digits

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 02-Aug-2021 05:36:35

392 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 ... Read More

Golang Program to check if two numbers are Amicable Numbers

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 31-Jul-2021 16:02:41

388 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: ... Read More

Golang Program to Print the Numbers in a Range (1, upper) without Using any Loops

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 31-Jul-2021 15:54:37

179 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 ( ... Read More

Golang Program to Find the Gravitational Force Acting Between Two Objects

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 31-Jul-2021 15:53:38

302 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 ... Read More

Golang Program to Find the Area of a Triangle Given All Three Sides

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 31-Jul-2021 15:52:40

351 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 ... Read More

Golang Program to Check if a Number is a Perfect Number

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 31-Jul-2021 15:49:58

416 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 ... Read More

Golang Program to Find the Numbers which are Divisible by 7 and Multiple of 5 in a Given Range

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 31-Jul-2021 15:48:27

401 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 ... Read More

Advertisements