Computer Science, asked by Anirudhchilukuri101, 5 months ago

Write a program to print numbers from 1 to 100 except multiples of 3.

Answers

Answered by daya874
1

Explanation:

for counter in 1..100 if (counter % 3 == 0) && (counter % 5 == 0) puts 'FooBar' elsif (counter % 3 == 0) puts 'Foo' elsif (counter % 5 == 0) puts 'Bar' else puts counter endend

counter = 1while counter <= 100 if (counter % 3 == 0) && (counter % 5 == 0) puts 'FooBar' elsif (counter % 3 == 0) puts 'Foo' elsif (counter % 5 == 0) puts 'Bar' else puts counter end counter += 1end # nerd version (1..100).each { |number| op = [] if number%3==0 op.push("Foo") end if number%5==0 op.push("Bar") end puts op.size > 0 ? op.join("") : number.to_s}

Similar questions