Assignment Math
Assignment Math
Total Marks: 20
Instructions:
Write a program that takes an integer as input and checks whether it is even or odd.
Example:
Input: 4
Output: Even
Input: 7
Output: Odd
Write a program that calculates the sum of all natural numbers up to a given number
using a for loop.
Example:
Input: 5
Output: 15 // 1+2+3+4+5
Problem 3: Multiplication Table (5 marks)
Write a program that generates the multiplication table of a given number using a
while loop.
Input: 3
Output:
3*1=3
3*2=6
3*3=9
...
3 * 10 = 30
Write a program to check whether a given number is a prime number or not using a
do-while loop.
Example:
Input: 11
Output: Prime
Input: 15
Output: Not Prime
Bonus Problem (Optional): Leap Year Checker (2 marks - Extra Credit)
Write a program that checks whether a given year is a leap year or not using a
switch statement.
Example:
Input: 2020
Output: Leap Year
Input: 2019
Output: Not a Leap Year
Hints: A year is a leap year if it is divisible by 4 but not by 100, except if it is also
divisible by 400.
Submit your source code in a single word document/ pdf by May 30, 2024.