Assignment: Basic Programming in C++
Total Marks: 20
Instructions:
1. Write all programs in C++.
2. Include comments in your code to explain your logic.
3. Test your programs thoroughly.
4. Submit your source code files.
Problem 1: Even or Odd Checker (5 marks)
Write a program that takes an integer as input and checks whether it is even or odd.
• Input: An integer number.
• Output: Print "Even" if the number is even, otherwise print "Odd".
Example:
Input: 4
Output: Even
Input: 7
Output: Odd
Problem 2: Sum of Natural Numbers (5 marks)
Write a program that calculates the sum of all natural numbers up to a given number
using a for loop.
• Input: A positive integer n.
• Output: Print the sum of all natural numbers from 1 to n.
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: An integer number.
• Output: Print the multiplication table of the input number from 1 to 10.
Example:
Input: 3
Output:
3*1=3
3*2=6
3*3=9
...
3 * 10 = 30
Problem 4: Prime Number Checker (5 marks)
Write a program to check whether a given number is a prime number or not using a
do-while loop.
• Input: An integer number.
• Output: Print "Prime" if the number is prime, otherwise print "Not Prime".
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.
• Input: An integer representing a year.
• Output: Print "Leap Year" if the year is a leap year, otherwise print "Not a Leap
Year".
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.