Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 74 of 102

Golang Program to Create a Class and Compute the Area and Perimeter of a Circle

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 556 Views

To compute the area and perimeter of a circle, we can take following steps −Define a struct with circle properties such as radius.Define a method to calculate the area of the circle.Define a method to calculate the perimeter of the circle.In the main method, take the user's input for circle's radius.Instantiate the circle with the radius.Print the area of the circle.Print the perimeter of the circle.Examplepackage main import (    "fmt"    "math" ) type Circle struct {    radius float64 } func (r *Circle)Area() float64{    return math.Pi * r.radius * r.radius } func (r *Circle)Perimeter() float64{    return ...

Read More

Golang Program to create a Class that can perform basic Calculator Operations

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

To create a class that can perform basic calculator operations, we can take following StepsWe can define a Calculator class with two numbers, a and b.Define a member method to calculate the addition of two numbers.Define a member method to calculate the multiplication of two numbers.Define a member method to calculate the division of two numbers.Define a member method to calculate the subtraction of two numbers.In the main method, declare two variables, a and b.Get an instance of Calculator.Initialize a choice variable, based on which mathematical operations could be performed.Examplepackage main import (    "fmt" ) type Calculator struct { ...

Read More

Golang Program to Calculate the Average of Numbers in a Given List

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

Input array is: [2, 4, 1, 6, 5]Sum = 2 + 4 + 1 + 6 + 5 => 18Average = 18/5 => 3.6 ~ 3To calculate the average of numbers in a given list, we can take following steps −Let's take an input list of numbers.Find the sum of numbers using sum() method.The sum method calculates the sum of numbers by iterating the given list.Print the average by dividing the sum with the length of the given list.Examplepackage main import (    "fmt" ) func sum(arr []int) int{    result := 0    for _, i :=range arr { ...

Read More

Golang Program to Read a Number (n) and Compute (n+nn+nnn)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 414 Views

Let's read a number, n=5Then, nn=55 and then nnn=555res = 5 + 55 + 555 => 615To read a number (n) and compute (n+nn+nnn), we can take the followingStepsDefine a variable, n.Print a statement to get the number, n.Take user input for variable, n.Make an expression for (n + nn + nnn).Convert the expression into numbers.Compute the sum of the expression.Examplepackage main import (    "fmt"    "strconv" ) func main(){    var n int    fmt.Print("Enter value of n: ")    fmt.Scanf("%d", &n)    t1 := fmt.Sprintf("%d", n)    t2 := fmt.Sprintf("+%d%d", n, n)    t3 := fmt.Sprintf("+%d%d%d", n, ...

Read More

Golang Program to read the marks of subjects and display the Grade

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 650 Views

Let's enter the marks: 89 56 90 67 99Sum of the marks is: 89+56+90+67+99 => 401Avg. = 401/5 = 80.1The steps are as follows:Define variables for 5 subjects.Enter marks for 5 subjects.Find average of the marks to find grade.Use if else block to print grade.Examplepackage main import "fmt" func main(){    var sub1, sub2, sub3, sub4, sub5 int    fmt.Println("Enter marks of the five subjects:")    fmt.Scanf("%d", &sub1)    fmt.Scanf("%d", &sub2)    fmt.Scanf("%d", &sub3)    fmt.Scanf("%d", &sub4)    fmt.Scanf("%d", &sub5)    avg:=(sub1+sub2+sub3+sub4+sub5)/5    if avg>=90{       print("Grade: A")    }else if avg>=80 && avg=70 && avg=60 && avg

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 415 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.Examplepackage 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

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 643 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.Examplepackage main import "fmt" func main(){    var a, b, c ...

Read More

Golang Program to Print Odd Numbers Within a Given Range

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 492 Views

To print odd number in a range, we can take two inputs, a and b, for lower and upper limits.Examplea = 2 and b = 9Numbers between a and b are: 2, 3, 4, 5, 6, 7, 8, 9Odd numbers are: 3, 5, 7, 9StepsDefine two numbers, a and b.Take user inputs for the numbers, a and b.Iterate the number between a and b.Find the modulo of 2, print the number if modulo of 2 of that number is not zero.Examplepackage main import "fmt" func main(){    var a, b int    fmt.Print("Enter lower limit number: ")    fmt.Scanf("%d", &a) ...

Read More

Golang Program to Find the Smallest Divisor of an Integer

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 455 Views

Consider that the integer is: 75Divisor of that integer is: 3, 5, 15, ..., 75The smallest divisor is: 3StepsTake an integer from the user.Initialize a variable (res) with that number.Use a for loop where the value of i ranges from 2 to the integer.If the number is divisible by i, compare with res. If res > i, then update res with i.Exit from the loop and print res.Examplepackage main import "fmt" func main(){    var n int    fmt.Print("Enter the number: ")    fmt.Scanf("%d", &n)    res := n    for i:=2; i

Read More

Golang Program to Count the Number of Digits in a Number

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 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.Examplepackage 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
Showing 731–740 of 1,016 articles
« Prev 1 72 73 74 75 76 102 Next »
Advertisements