This is your first take home lab exercise. All take home labs are automatically graded by the CourseMarker and do not count as part of the continuous assessment grades. However, to better prepare yourself for the sit-in labs (which constitutes 5% weightage of the course each) you are strongly encouraged to attempt all questions.
In general, you should use the standard I/O using
scanf for input and
printf for output in your
programs, unless otherwise stated.
If you have any questions, you may post your queries in the IVLE forum. You
should take note that your program output should exactly match the
output given in the sample run.
There is no deadline for your take home labs. However you are encouraged to practice them as early as possible.
Given three input integers, determine if one of the number is the sum of the other two. If so, print out that number, otherwise print "No". You should terminate your final output with a new line character ("\n").
Sample run using interactive input (user's input shown in blue; output shown in bold purple):
| 3 7 5 No |
Another sample run
| 12 7 5 12 |
Another sample run
| 7 5 12 12 |
Another sample run
| 7 5 13 No |
Your program should be coded in a single file called "IsSum.c"
Submit your program through CourseMarker.
Given a 6 digit number k ( 100000 ≤ k ≤ 999999), print out the the nth ( 1 ≤ n ≤ 6) digit (n is the input given by the user). If the input is not valid (e.g. k = 99999 or n = -1) then print the word invalid. The first digit is the digit on the right-most of the number.
You should terminate your final output with a new line character ("\n").
Sample run using interactive input (user's input shown in blue; output shown in bold purple):
| 375416 4 5 |
Another sample run:
| 987654 1 4 |
Another sample run (which is invalid because n is not between 1 and 6):
| 999999 -1 invalid |
Another sample run (which is invalid because k is not a 6 digit number):
| 12345 3 invalid |
Your program should be coded in a single file called "NDigit.c"
Submit your program through CourseMarker.
A particular credit card awards you five points for every block of eight Singapore dollars (SGD) spent. No points are given for partial blocks. So, if you spend SGD 16, you will get ten points. If you spend SGD 23, you will still get ten points.
Furthermore, every block of eight points is worth five miles. Once again, no miles are awarded for partial blocks. So, if you have 40 points, you will get 25 miles. If you have 45 points, you will still get 25 miles.
By default, the credit card company always gives you double the amount of points, called double rewards. So, if you spend SGD 16, instead of getting ten points, you will get 20 points.
But there are certain shops (called platinum shops) which have a special arrangement with the credit card company. If you spend money at these platinum shops, you will get platinum rewards, and instead of getting double points, you will get 10 times the normal amount of points. So, if you spend SGD 16 at a platinum shop, instead of getting ten points, you will get 100 points.
Write a program called Rewards.c that prompts the user for the amount of money spent, as well as the type of spending (ask the user to key in 1 for double spending, 2 for platinum spending). Your program will compute and display the number of miles earned.
You should be very careful with your output. Even an extra space will be marked as a mistake (thus failing all test cases) by CourseMarker. To prevent that mistake double check your output. The query ("Enter amount of spending in SGD: ") is considered as part of your output.
Sample run using interactive input (user's input shown in blue; output shown in bold purple):
| Enter amount of spending
in SGD: 123 Enter type of rewards (1=double, 2=platinum): 1 Your spending is: SGD 123 Type of rewards: 1 Number of points earned: 150 Number of miles earned: 90 |
Another sample run
| Enter amount of spending
in SGD: 123 Enter type of rewards (1=double, 2=platinum): 2 Your spending is: SGD 123 Type of rewards: 2 Number of points earned: 750 Number of miles earned: 465 |
Your program should be coded in a single file called "Rewards.c"
Submit your program through CourseMarker.
We can easily encode letters as numbers in the order of their appearance alphabetically. For example A = 1, B = 2... Z = 26. In this task, given a numerical input and a character input, print valid if the number matches the character and invalid otherwise.
All character inputs are in their upper-case. You should terminate your output with a new line character ("\n").
Sample run using interactive input (user's input shown in blue; output shown in bold purple):
| 6 F valid |
Another sample run:
| 6 A invalid |
Your program should be coded in a single file called "Encode.c"
Submit your program through CourseMarker.