0% found this document useful (0 votes)
28 views1 page

TP2 CPP 23 - 24

The document outlines 10 programming exercises for a lab work assignment focusing on flow control instructions in C++ using conditional statements and loops. The exercises include programs to check if a number is even or odd, determine if a year is a leap year, play a number guessing game, calculate factorials and Fibonacci sequences, check for palindromes, and build a menu-driven calculator.

Uploaded by

Lilia Bournane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

TP2 CPP 23 - 24

The document outlines 10 programming exercises for a lab work assignment focusing on flow control instructions in C++ using conditional statements and loops. The exercises include programs to check if a number is even or odd, determine if a year is a leap year, play a number guessing game, calculate factorials and Fibonacci sequences, check for palindromes, and build a menu-driven calculator.

Uploaded by

Lilia Bournane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Electronic Department

M1 ESE

LAB work 2
Objectives:
1) Practice working with flow control instructions inC++ using:
Conditional execution: if … else
Loops : for loops, while loops and nested loops

Work to do:
The work consists of 10 exercises.

 Even or Odd: Write a program that takes an integer as input and determines whether it's
even or odd.

 Leap Year Checker: Create a program that checks if a given year is a leap year. Leap
years are divisible by 4 but not divisible by 100, except when they are divisible by 400.

Ex: 2020 is a leap year

 Guess the Number Game: Implement a number-guessing game where the computer
selects a random number between 1 and 100, and the player has to guess it. Provide hints if
the guess is too high or too low.

Hint: Look for the functions “rand” and “srand”.

 Factorial Calculator: Write a program that calculates the factorial of a given positive
integer using a loop.

 Sum of Digits: Create a program that calculates the sum of the digits of a positive integer.

 Multiplication Table: Generate a multiplication table for a given number, from 1 to 10.

 Fibonacci Sequence: Write a program to print the first n numbers in the Fibonacci
sequence.

 Palindrome Checker: Implement a program that checks whether a given string is a


palindrome (reads the same backward as forward).

 Grade Calculator: Create a program that takes 5 numerical scores as inputs, calculates the
mean value and outputs the corresponding academic distinction/grade:

Excellent: 18 ≤ score≤ 20 ; Very good: 16 ≤ score< 18 ; Good: 14 ≤ score<16

Fairly good: 12 ≤ score< 14; Satisfactory: 10 ≤ score< 12 ; Postponed: score<10

Menu-Driven Calculator: Design a simple menu-driven calculator that can perform basic
arithmetic operations (addition, subtraction, multiplication, division) based on user input.

You might also like