Convert Celsius to Fahrenheit in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:33:13

527 Views

StepsTake the value of temperature in Celsius and store it in a variable.Convert it to Fahrenheit.Print the final result.Enter the temperature in Celsius: 32Temperature in Fahrenheit is: 89.6Enter the temperature in Celsius: 48Temperature in Fahrenheit is: 118.4ExplanationUser must first enter the value of temperature in Celsius.Using the formula: f=(c*1.8)+32, convert Celsius to Fahrenheit.Print the temperature in Fahrenheit.Example Live Demopackage main import "fmt" func main(){    var n int    fmt.Print("Enter the temperature in Celsius:")    fmt.Scanf("%d", &n)    f:=(float32(n)*1.8)+32    fmt.Println("Temperature in Fahrenheit is:", f) }OutputEnter the temperature in Celsius:32 Temperature in Fahrenheit is: 89.6Read More

Convert Centimeters to Feet and Inches in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:32:26

314 Views

StepsTake the height in centimeters and store it in a variable.Convert the height in centimeters into inches and feet.Print the length in inches and feet.Enter the height in centimeters: 50The length in inches: 19.7The length in feet: 1.64Enter the height in centimeters: 153The length in inches: 60.28The length in feet: 5.02ExplanationUser must enter the height in centimeters.The height in centimeters is multiplied by 0.394 and stored in another variable which now contains the height in inches.The height in centimeters is multiplied by 0.0328 and stored in another variable which now contains the height in feet.The converted height in inches and ... Read More

Check Whether a Given Year is a Leap Year in Go

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

2K+ Views

StepsTake the value of the year as input.Using an if-statement, check whether the year is a leap year or notPrint the final result.Enter the year to be checked: 2016The year is a leap year!Enter the year to be checked: 2005The year isn't a leap year!ExplanationUser must first enter the year to be checked.The if statement checks if the year is a multiple of 4 but isn't a multiple of 100 or if it is a multiple of 400 (not every year that is a multiple of 4 is a leap year).Then, the result is printed.Example Live Demopackage main import "fmt" func ... Read More

Golang Program to Print an Inverted Star Pattern

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:30:43

343 Views

StepsTake a value from the user and store it in a variable, n.Use a for loop where the value of i ranges between the values of n-1 and 0 with a decrement of 1 with each iteration.Multiply the empty spaces with n-i and '*' with i and print both of them.Exit.ExplanationUser must first enter the value and store it in a variable, n.The for loop enables i to range between n-1 and 0 with a decrement of 1 with each iteration.For each iteration, " " is multiplied with n-i and '*' is multiplied with i to ensure correct spacing of ... Read More

Compute Simple Interest in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:11:05

171 Views

StepsRead the values for principal amount, rate and time.Using the formula, compute the simple interest.Print the value for the computed interest.Enter the principal amount: 200Enter the time(years): 5Enter the rate: 5The simple interest is: 50Enter the principal amount: 70000Enter the time(years): 1Enter the rate: 4The simple interest is: 2800ExplanationUser must enter the values for the principal amount, rate and time.The formula: (amount*time*rate)/100 is used to compute the simple interest.The simple interest is later printed.Example Live Demopackage main import "fmt" func main() {    var principal, time, rate int    fmt.Print("Enter the principal amount: ")    fmt.Scanf("%d", &principal)    fmt.Print("Enter the time ... Read More

Golang Program to Print an Identity Matrix

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:09:29

263 Views

The steps to print an identity matrix using Golang is as follows :Take a value from the user and store it in a variable, n.Use two for loops where the value of j ranges between the values of 0 and n-1 and the value of i also ranges between 0 and n-1.Print the value of 1 when i is equal to j, and 0 otherwise.Case 1:Enter a number: 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1Case 2:Enter a number: 5 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1Example Live Demopackage main import "fmt" func main(){    var n int    fmt.Print("Enter a number: ")    fmt.Scanf("%d", &n)    for i:=0; i

Print Natural Numbers Summation Pattern in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:07:59

288 Views

Let's suppose the number is: 4Then, the Summation Patten would be:1 = 11 + 2 = 31 + 2 + 3 = 61 + 2 + 3 + 4 = 10StepsTake a value from the user and store it in a variable, n.Use two for loops where the value of t ranges between the values of 1 and n and the value of i ranges between 1 and t.Print the value of i and '+' operator.Find the sum of elements in the list.Print '=' followed by the total sum.Exit.Example Live Demopackage main import "fmt" func main(){    var n int    fmt.Print("Enter number: ")    fmt.Scanf("%d", &n)    for t:=1; t

Read a Number N and Print the Series 1+2+...+N in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:05:51

136 Views

StepsTake a value from the user and store it in a variable (n).Use a for loop where the value of i ranges between the values of 1 and n.Print the value of i and '+' operator.Find the sum of elements in the list.Print '=' followed by the total sum.Exit.ExplanationUser must first enter the value and store it in a variable, n.The for loop enables i to range between 1 and n (as n+1 is not included).For each iteration, the value of i is printed.'+' operator is printed only if iExample Live Demopackage main import "fmt" func main(){    var n int ... Read More

Print Integers Between a Range Not Divisible by 2 or 3 in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:01:21

401 Views

Let's assume the range is from 0 to 50. We have to print all the integers that aren't divisible by either 2 or 3.StepsUse a for loop ranging from 0 to 50.Then, use an if statement to check if the number isn't divisible by both 2 and 3.Print the numbers satisfying the condition.ExplanationThe for loop ranges from 0 to 50.The number is divided by 2 and 3.If the remainder ≠ 0, the number isn't divisible by either 2 and 3.The number satisfying the condition is printed.Example Live Demopackage main import "fmt" func main(){    for i:=1; i

Count the Number of Digits in a Number using Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 15:00:03

4K+ Views

Suppose the number is: 123456Count of digits in the given number is: 6To count the number of digits in a number, we can take followingStepsTake the value of the integer and store in a variable.Using a while loop, get each digit of the number and increment the count each time a digit is obtained.Print the number of digits in the given integer.Example Live Demopackage main import "fmt" func main(){    var n int    fmt.Print("Enter the number: ")    fmt.Scanf("%d", &n)    count := 0    for n >0 {       n = n/10       count++   ... Read More

Advertisements