Computer Science, asked by ruchitha09, 2 months ago

write a ruby script to create a new string which is 'n' copies of a given string where 'n' is a non negative integer?​

Answers

Answered by Morriselasesino98
1

Heyy here is your answer

Ruby Basic Exercises: Create a new string which is n copies of a given string where n is a non-negative integer

def multiple_string(str, n)

def multiple_string(str, n) return str*n

def multiple_string(str, n) return str*nend

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:a

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:aaa

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:aaaaaa

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:aaaaaaaaaa

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:aaaaaaaaaaaaaaa

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:aaaaaaaaaaaaaaaFlowchart:

def multiple_string(str, n) return str*nendprint multiple_string('a', 1),"\n"print multiple_string('a', 2),"\n"print multiple_string('a', 3),"\n"print multiple_string('a', 4),"\n"print multiple_string('a', 5),"\n"Output:aaaaaaaaaaaaaaaFlowchart:Flowchart: Create a new string which is n copies of a given string where n is a non-negative integer

Hope this helps you

Similar questions