Advanced Data Structures in C++
Tutorial 1 on C++ Basics: Master C++ with this practical exercise
1. Write a Program to Print “Hello World” in the Console Screen.
2. Write a Program to Read and Print Number Input From the User.
3. Write a Program to Swap Two Numbers.
For Example,
// Variables initally
a = 10, b = 250
// After execution
Output: a = 250, b = 10
4. Write a Program to Find Compound Interest.
Principle = 25000
Rate = 12%
Time = 5 Years
Output: Compound Interest = 19058.54
5. Write a Program to Check Even or Odd Integers.
Number = 28
Output: 28 is Even Number.
6. Write a Program to Find the Largest Among 3 Numbers.
Given Numbers: a = 10, b = 21 and c = 4
Output: b is the largest.
7. Write a Program to Check if a Given Year Is a Leap Year.
Input: 2020
Output: 2020 is a Leap Year
8. Write a Program to Check Whether a Number Is Prime or Not.
Number to Check = 29
Output: 29 is a prime number.
9. Write a Program to Check Whether a Number Is a Palindrome or Not.
Number to Check = 1231
Output: 1231 is not a palindrome number.
10. Write a Program to Make a Simple Calculator.
Input:
Enter the Number: 10 25
Enter a for addition,
s for substraction,
Mr. CONSTANTINE N. MBUFUNG Page 1
Advanced Data Structures in C++
m for multiplication,
d for division.
{{if m is entered}}
Output: 250
11. Write a Program to Reverse a Sentence Using Recursion.
Sentence = "Quick brown fox";
Output: xof nworb kciuQ
12. Write a Program for Fibonacci Numbers Using Recursion.
N = 12
Output: 144
13. Write a Program to Swap Two Numbers Using a Function.
// in main function
a = 10, b = 22
Output: a = 22, b = 10
14. Write a Program to Check if Two Arrays Are Equal or Not.
An array is said to be equal if the elements at the given index are equal in both arrays.
arr1[] = {5, 8, 3}
arr2[] = {5, 8, 11, 2}
Output: arr1[] and arr2[] are not equal.
15. Write a Program to Calculate the Average of All the Elements Present in an Array.
For Example,
arr[] = {10, 22, 45, 11}
Output: Average = 24.5
16. Write a Program to Find the Maximum and Minimum in an Array.
arr[] = {10, 12, 45, 48, 22, 18}
Output:
Maximum = 48
Minimum = 10
17. Write a Program to Find the Length of a String.
Mr. CONSTANTINE N. MBUFUNG Page 2
Advanced Data Structures in C++
str = "GeeksforGeeks"
Output: Length of str = 13
18. Write a Program to Compare Two Strings.
str1 = "Geeks"
str2 = "geeks"
Output: str1 and str2 are not equal.
19. Write a Program to Check if the String Is Palindrome.
Similar to a palindrome number, a palindrome string is a string that is equal to its reverse.
str = "naman"
Output: str is a palindrome string.
20. Write a Program to Print a Simple Full Pyramid Pattern.
In this problem, you have to print the simple pyramid pattern shown below:
*
**
***
****
*****
Mr. CONSTANTINE N. MBUFUNG Page 3