Open In App

Ruby | Vector zero() function

Improve
Improve
Like Article
Like
Save
Share
Report

The zero() is an inbuilt method in Ruby returns the vector of size N with elements equals to 0.

Syntax: Vector.zero(N)

Parameters: The function accepts a parameter which represents the size of the array.

Return Value: It returns the vector of size N with elements equals to 0. 
 

Example 1:  

Ruby




#Ruby program for zero method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vector
    vec1
    = Vector.zero(4)
 
#prints the new vector
          puts vec1


Output

Vector[0, 0, 0, 0]

Example 2

Ruby




#Ruby program for zero method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vector
    vec1
    = Vector.zero(3)
 
#prints the new vector
          puts vec1


Output

Vector[0, 0, 0]

 


Last Updated : 19 Jan, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads