

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang program to calculate the absolute and scale of a vertex.
Example
Abs(x, y) => √(x)2+(y)2
Scale(f) => (x*f, y*f)
Approach
Define a vertex as a struct.
Initialize the vertex with some x and value.
Define a method to calculate absolute(x, y).
Define a method to calculate scale(x*f, y*f).
Example
package main import ( "fmt" "math" ) type Vertex struct { X, Y float64 } func Abs(v Vertex) float64{ return math.Sqrt(v.X*v.X + v.Y*v.Y) } func Scale(v *Vertex, f float64) { v.X = v.X * f v.Y = v.Y * f } func main() { v := Vertex{3, 4} fmt.Println("Given vertex is: ", v) fmt.Println("Absolute value of given vertex is: ", Abs(v)) f := 10.0 fmt.Printf("After scaling by %0.1f new vertex is: ", f) Scale(&v, f) fmt.Println(v) fmt.Println("Absolute value of given vertex is: ", Abs(v)) }
Output
Given vertex is: {3 4} Absolute value of given vertex is: 5 After scaling by 10.0 new vertex is: {30 40} Absolute value of given vertex is: 50
- Related Questions & Answers
- Program to calculate vertex-to-vertex reachablity matrix in Python
- Golang Program to Calculate the Average of Numbers in a Given List
- Write a Golang program to calculate the sum of elements in a given array
- Pendent Vertex, Isolated Vertex and Adjacency of a graph
- C++ program to find the vertex, focus and directrix of a parabola
- Java Program to find the vertex, focus and directrix of a parabola
- C++ Program to Find the Vertex Connectivity of a Graph
- Calculate the absolute value of float values in Numpy
- Calculate the absolute value of complex numbers in Numpy
- Python Program for Finding the vertex, focus and directrix of a parabola
- Finding the vertex, focus and directrix of a parabola in Python Program
- How to calculate absolute value in Python?
- C/C++ Program for Finding the vertex, focus and directrix of a parabola?
- Calculate the absolute value element-wise in Numpy
- Program to calculate the area of a Tetrahedron
Advertisements