Programming Assigment 2 (Deadline: April 20th Monday 23:59)
Problem
Write a program in C to do the following tasks:
-prints the calendar for a given month in 2009,
-finds the prime factors of a given number,
-and determines fibonacci numbers from a list of numbers.
Input
All input is given through the terminal. Your program should first read a line of input stating the task to be carried out. The first line will be:
- 'c' for the calendar task,
- 'p' for the prime factors task and
- 'f' for the fibonnaci numbers task.
The format of the remaining lines will depend on the task specified in the first line. The second line will contain:
- a positive integer between 1 and 12 specifying the month whose calendar should be printed, for the calendar task.
- a positive integer between 2 and 1000 specifying the number whose prime factors are to be found, for the prime factors task.
- 5 positive integers between 1 and 2000000000, separated by spaces specifying the list of numbers for the fibonacci numbers task.
Output
The format of the output of your program depends on the task specified in the first input line.
For the calendar task, your program should output the letters S,M,T,W,R,F,S in the order listed here on the first line. The letters should be separated by tabs. Then, your program should output positive integers representing the days of the month on multiple lines. They should be formatted in a calendar style. More specifically, the days should be in ascending order and must be aligned by tabs to match the weekdays that appear on top of them. Output the days using the minimum number of lines possible. Notice that the output does not contain any spaces. All separation and alignment is done with tabs.
For the prime factors task, your program should output a sequence of integers separated by spaces on a single line. These should be the prime factors of the integer specified in the input. The factors should be in ascending order. If a factor is repeated, it should be printed only once.
For the fibonacci numbers task, your program should output a sequence of integers separated by spaces on a single line. This sequence should be a subsequence of the 5-number sequence specified in the input. It should consist of all of the fibonacci numbers listed in the input. The numbers should be listed in the order they are given in the input. If there are no fibonacci numbers in the input sequence, your program should output nothing.
Sample Input 1
c
8
Sample Output 1(corresponding to the sample input 1)
S M T W R F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Sample Input 2
p
12
Sample Output 2
2 3
Sample Input 3
f
4 13 45 34 1
Sample Output 3
13 34 1
Assumptions and Constraints
For the fibonacci task: You can safely assume that the numbers in the input sequence will be distinct.
Submission
Submit your source code for the program (.c file) through the assignment submission system.