![]() |
.. (לתיקייה המכילה) | |
Am I limited to use specific material? | |
No, in this homework alone you can use any material you want. However, lectures 1-5 and tutorials 1-6 should be sufficient to solve the HW. |
In Question #1: What should the program output if the input contains 0-2 numbers and then EOF. | |
If the input contains 0 or 1 numbers, the program should print "Invalid Input". However, 2 numbers are valid Fibonacci series and the program should output these numbers. |
In Question #1: How should I know if the input is in valid format or not? | |
The idea is to use scanf() to read an integer number. If the input is not in the right format, use scanf return value to acknowledge that (tutorial 4). Handling invalid input should not take more than 2-3 lines of code. |
In Question #1: If the input is "0 1 1 4.8" should the program print "not fibonacci series" or "invalid input"? | |
First, we do not check such cased (both invalid input and not fibonacci series). However, the right behavior should be to print "not fibonacci series". Using scanf("%d"), it reads 0, 1, 1 and 4. At this point the program discovers that this in not a fibonacci series and stops. If the input is "0 1 1 2.8", then scanf reads 0, 1, 1, 2, and then it tries to read the '.'. Because the '.' is not a number, scanf will return an error, and the program should terminate with "Invalid input" (Note, first 'I' is big case, other 'i'-s in small cases). If you are not sure what scanf do in case of error, please try to run it on your computer. Finally note that ctrl+z must be inserted after an enter, at the beginning of a new line (otherwise scanf will not always return EOF). |
In Question #3: Should we check the sum of the secondary diagonal (lower left corner to upper right corner) as well? | |
You should check the secondary diagonal, and its sum must be equal to all the following: sum of the main diagonal, sum of each row and sum of each column. |