11. Write a Ruby program to find the smallest number in an array.

Required Input:

[8, 3, 5, 2, 7]

Expected Output:

2

Code In Ruby

# Predefined array array = [8, 3, 5, 2, 7] # Your logic here

Run Code?

Click Run Button to view compiled output

12. Write a program that prints numbers from 1 to 100, replacing multiples of 3 with "Fizz," multiples of 5 with "Buzz," and multiples of both with "FizzBuzz."

Required Input:

1 to 100

Expected Output:

1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz

Code In Ruby

# Your logic here

Run Code?

Click Run Button to view compiled output

13. Create a method to merge two arrays and remove duplicates.

Required Input:

Array1: [1, 2, 3], Array2: [2, 3, 4]

Expected Output:

[1, 2, 3, 4]

Code In Ruby

# Predefined arrays array1 = [1, 2, 3] array2 = [2, 3, 4] # Your logic here

Run Code?

Click Run Button to view compiled output

14. Write a program to check if an array contains a specific element.

Required Input:

Array: [10, 20, 30, 40], Element: 30

Expected Output:

true

Code In Ruby

# Predefined array and element array = [10, 20, 30, 40] element = 30 # Your logic here

Run Code?

Click Run Button to view compiled output

15. Write a method that takes a hash and prints each key-value pair.

Required Input:

{name: "John", age: 25, city: "New York"}

Expected Output:

name: John
age: 25
city: New York

Code In Ruby

# Predefined hash hash = {name: "John", age: 25, city: "New York"} # Your logic here

Run Code?

Click Run Button to view compiled output

16. Create a Ruby program to reverse the elements in an array.

Required Input:

[1, 2, 3, 4, 5]

Expected Output:

5
4
3
2
1

Code In Ruby

# Predefined array array = [1, 2, 3, 4, 5] # Your logic here

Run Code?

Click Run Button to view compiled output

17. Write a method that checks if a string contains a specific substring.

Required Input:

"hello world", "world"

Expected Output:

true

Code In Ruby

# Predefined string and substring string = "hello world" substring = "world" # Your logic here

Run Code?

Click Run Button to view compiled output

18. Create a method to capitalize the first letter of each word in a string.

Required Input:

"ruby is fun"

Expected Output:

Ruby Is Fun

Code In Ruby

# Predefined string string = "ruby is fun" # Your logic here

Run Code?

Click Run Button to view compiled output

19. Write a program to generate the Fibonacci sequence up to a given number.

Required Input:

10

Expected Output:

0
1
1
2
3
5
8

Code In Ruby

# Predefined number num = 10 # Your logic here

Run Code?

Click Run Button to view compiled output

20. Write a Ruby program to count the frequency of each character in a string.

Required Input:

"hello"

Expected Output:

h: 1
e: 1
l: 2
o: 1

Code In Ruby

# Predefined string string = "hello" # Your logic here

Run Code?

Click Run Button to view compiled output

ad vertical

2 of 3