You are on page 1of 2

Modul 6 Quiz

Conditional & Iterative Structures


1. Write a program that takes an odd number as input. Your program has to make sure that the input is really an odd number, otherwise user should be asked to input a number again until an odd number is inputted.
Input an odd number : 8 It is not an odd number! Input an odd number : 7 * *** ***** ******* ***** *** *

2. Write a program that takes an even number, greater than 2 as input. Your program has to make sure that the input is really greater than 2 and an even number, otherwise user should be asked to input a number again until the required number is inputted.
Input an odd number greater than 2 : 2 It is not a valid input! Input an odd number greater than 2 : 10 ********** **** **** *** *** ** ** * * ** ** *** *** **** **** **********

3. Fibonacci is a sequence that has a rule : nk+2 = nk+1 + nk , k>=0 , n0=0 , n1=1. Hence, Fibonacci sequence is like this : 0, 1, 1, 2, 3, 5, 8, 13, 20, This means that the 3rd number in Fibonacci sequence is 3, the 7th is 13, etc. Write a program that takes a number n as input, and generate the n-th number of Fibonacci sequence. Following is the example of the output.

Input a number : 8 The 8-th number of Fibonacci sequence is 20.

4. BONUS QUESTION. This question is worth a perfect score 100, which means if you can solve this, you dont need to solve questions in number 1, 2, and 3. It is true that one of our rules in the beginning of the class is that we are to respect ourselves, which means saying I cant solve this question isnt tolerable in this class, but I dont think its wise either to force yourselves in solving this question if youre not capable YET. So be wise, its your call. Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a give number of years, N. N is positive and will not exceed 400 (Note that the start year is nineteen hundred, not 1990). There are a few facts you need to know before you can solve this problem : - January 1, 1990 was on a Monday. - Thirty days has September, April, June, and November, all the rest have 31 except for February which has 28 except in leap years when it has 29. - Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 is a leap year, but 1990 is not). - The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1900, 1900, and 2100 are not leap years, but 2000 is a leap year. Do not use any built-in date functions in C++. Dont just precompute the answers either. The output should contain seven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, , Friday. Following is the example of how your program should look like.
Input a number : 20 36 33 34 33 35 35 34

You might also like