logo codesdope
Level 1
1.
Take input of length and breadth of a rectangle from user and print area of it.
Answer
puts "Enter length"
length = gets.chomp.to_i
puts "Enter Breadth"
breadth = gets.chomp.to_i
puts length*breadth
									

2.
Ask user to give two float input for length and breadth of a rectangle and print area type casted to int.
Answer
puts "Enter length"
length = gets.chomp.to_f
puts "Enter Breadth"
breadth = gets.chomp.to_f
puts (length*breadth).to_i
									

3.
Take side of a square from user and print area and perimeter of it.
Answer
puts "Enter side"
side = gets.chomp.to_i
puts "Area is #{side*side}"
puts "Perimeter is #{4*side}"
									

4.
Take name, roll number and field of interest from user and print in the format below :
Hey, my name is xyz and my roll number is xyz. My field of interest are xyz.
Answer
puts "Enter name"
name = gets.chomp
puts "Enter roll number"
roll = gets.chomp
puts "Field of interests"
interest = gets.chomp
puts "Hey, my name is #{name} and my roll number is #{roll}. My field of interests are #{interest}"
									

5.
Write a program to find square of a number.
E.g.-
INPUT : 2        OUTPUT : 4
INPUT : 5        OUTPUT : 25
Answer
puts "Enter number to find the square of it"
number = gets.chomp.to_i
puts number**2
									

6.
Take two different string input and print them in same line. E.g.-
INPUT : Codes
Dope
OUTPUT : CodesDope
Answer
puts "Enter first string"
first = gets.chomp
puts "Enter seconnd string"
second = gets.chomp
final = first+second
puts final
									
Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.