Skip to content

Latest commit

 

History

History

week05

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Loops

Question 1 - Numbeeeers

Write a program that reads two integers N and K. Then, it prints numbers from N to K to the screen.

INPUT OUTPUT
5 9 5 6 7 8 9
2 3 2 3

Question 2 - Hooping Numbers

Write a program that reads 3 integers A, B and T from the user. Then prints numbers from A to B with increment of T. Assume that B > A.

INPUT OUTPUT
7 16 3 7 10 13 16
2 30 6 2 8 14 20 26

Question 3 - Even Numbeeeers

Write a program that reads two integers A and B. Then prints the sum of even numbers between A and B. Assume that B > A. A and B are included.

INPUT OUTPUT
3 8 18
2 13 42
3 5 4

Question 4 - Average Team

Write a program that reads a number N, then reads N more numbers. Calculate the average of those N numbers.

INPUT OUTPUT
4
4 9 5 2
5.0
1
8
8.0

Question 5 - Boom Boom POW

Write a program that takes 2 integers a and b, then prints the result of a^b (a*a*a...*a*a).

INPUT OUTPUT
3 4 81
2 10 1024

Question 6 - Fibonacci

Write a program which reads a positive integer number N , and prints the Nth fibonacci number. 0, 1, 1, 2, 3, 5, ...

F_0 = 0, F_1 = 1, F_n = F_(n-2) + F_(n-1)

INPUT OUTPUT
2 1
4 2
7 8

Question 7 - Second Largest

Write a program that will take nonnegative integers as inputs until the user enters 0. Then prints the difference between the largest two numbers among given inputs.

INPUT OUTPUT
12 25 3 8 0 13
15 1 2 3 8 5 0 7

Question 8 - Digiiiits

Write a program that takes a number and prints its total digit count and also even digit sum.

INPUT OUTPUT
542175 6 6
24680 5 20
135 3 0

Question 9 - Positive Mental Attitude

Write a program that will take integers as inputs until the user enters a negative number. Then shows the user the sum of all ODD non-negative numbers that is entered.

INPUT OUTPUT
4 7 45 9 2 0 0 5 8 -4 66
1 1 0 1 -1 3

Question 10 - Guess

Generate a random number between 1 and 100 (including 1 and 100). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right. Also print the number of tries.

Input Output
35
67
73
71
Too low!
Too low!
Too high!
You got it!
And it only took you 4 tries!

Question 11 - NoBig

Write a program that reads numbers until the entered number is greater than the previous entered number. Then print the average of all entered numbers except the last one. (At least two numbers will be entered)

INPUT OUTPUT
5 4 3 3 8 3.75
1 2 1.0
100 54 46 2 3 50.5

Question 12 - FizzBuzz

Take an integer N from the user as an input. And then print all the numbers from 1 to N (inclusive), but if a number is a multiple of 2, print "Fizz", if a number is a multiple of 3, print "Buzz", and if a number is a multiple of 6 print "FizzBuzz".

Input Output
6 1 Fizz Buzz Fizz 5 FizzBuzz
12 1 Fizz Buzz Fizz 5 FizzBuzz 7 Fizz Buzz Fizz 11 FizzBuzz

Question 13

Write a program that takes two nonnegative integers as input and finds their greatest common divisor.

13 91 -> 13
87 15 -> 3
432 0 -> 0
18 18 -> 18

Question 14

A number is said to be "Disarium" if the sum of its digits raised to their respective positions is the number itself. Write a program that determines whether a number is a Disarium or not.

75 ➞ False

7^1 + 5^2 = 7 + 25 = 32

135 ➞ True

1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135

Example Inputs/Outputs:

544 ➞ False

518 ➞ True

466 ➞ False

8 ➞ True