- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1082 Articles for Go Programming
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 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
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 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
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 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
454 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.Example Live Demopackage 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
250 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.Example Live Demopackage 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", ... Read More
995 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.Example Live Demopackage main import ( "fmt" ) func sum(arr []int) int{ result := 0 for _, i :=range arr ... Read More
893 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.Example Live Demopackage main import ( "fmt" ) type Calculator struct ... Read More
353 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.Example Live Demopackage 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{ ... Read More
399 Views
To find the area of a rectangle using classes, we can take following StepsDefine a struct with rectangle properties such as breadth and length.Define a method to calculate the area of the rectangle.In the main method, instantiate an object of rectangle.Call the struct method, i.e., Area, to calculate the area of the rectangle.Print the area of the rectangle.Example Live Demopackage main import ( "fmt" ) type Rectangle struct { breadth int len int } func (r *Rectangle)Area() int{ return r. len * r.breadth } func main(){ rectangle := Rectangle{ breadth: 10, ... Read More
737 Views
pre.prettyprint{width:99%!important;} a.demo{top:12px!important; float:right!important;}To read the contents of a file, we can take following steps −We can create a file called test.txt.Clean-up using defer statement.Write the contents of string.Call ReadFile() method to read the file.ReadFile reads the file named by filename and returns the contents.Print the content of the file.Example Live Demopackage main import ( "fmt" "io/ioutil" "log" "os" ) func CreateFile() { file, err := os.Create("test.txt") if err != nil { log.Fatalf("failed creating file: %s", err) } defer file.Close() _, err = file.WriteString("Welcome to Tutorials Point") if err ... Read More