lab_manual_Problem_solving_programming_in_cPP2024[1]
lab_manual_Problem_solving_programming_in_cPP2024[1]
Laboratory Manual
Course Type- Practical
Academic Session: June-Dec 2024
Submitted To Submitted By
Dr. Atul Nandwal Name :
Table of Contents
Exp. Page Experiment Date Submission Signature
No. Title of Experiment No. Date
WAP that accepts the marks of 4 12-Sep-24 13-Sep-24
5 subjects and finds the sum
and percentage
marks Obtained by the student.
1
WAP that calculates the 9 19-Sep-24 30-Sep-24
Simple Interest and Compound
Interest. The Principal,
2 Amount, Rate of Interest and
Time are entered through the
keyboard
WAP to calculate the area and 13 26-Sep-24 27-Sep-24
3 circumference of a circle.
WAP that accepts the 16 3-Oct-24 4-Oct-24
4 temperature in Centigrade and
converts into Fahrenheit using
the formula C/5=(F-32)/9
WAP that swaps values of two 18 10-Oct-24 11-Oct-24
5 variables using a third variable.
WAP that checks whether the 21 24-Oct-24 25-Oct-24
6 two numbers entered by the
user are equal or not
WAP to find the greatest of 24 7-Nov-24 8-Nov-24
7 three numbers.
WAP that finds whether a 27 14-Nov-24 22-Nov-24
8 given number is even or odd.
WAP that tells whether a given 29 21-Nov-24 22-Nov-24
year is a leap year or not.
9
WAP that accepts marks of five 32 28-Nov-24 29-Nov-24
subjects and finds percentage
10 and prints grades.
Write a program to calculate 36 12-Dec-24 13-Dec-24
the sum of the elements of an
11 array.
Create a program to 41 19-Dec-24 20-Dec-24
12 manage a student database
that stores their name, age,
and
grade.
[1]
Experiments with Results and Viva-Voice Questions
Experiment
1
Number
WAP that accepts the marks of 5 subjects and finds the sum and
Experiment Title percentage marks Obtained by the student.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Output/Result
Sample viva Q1. What formulae are used in this program to calculate the total marks and
question percentage?
Ans. The total marks are calculated by adding the marks obtained in each subject.
The percentage is calculated by dividing the total marks by 5.
Q3. Can this program be used to calculate the percentage of marks obtained
in more than five subjects?
Ans. No, this program is specifically designed to calculate the percentage of
marks obtained in five subjects only. If you need to calculate the percentage of
marks obtained in more subjects, you will need to modify the program accordingly.
Ans: The clrscr() function is used to clear the console screen before displaying the
output. It makes the output appear clean and more readable.
Q: What is C++?
A: .cpp
A: Data types in C++ specify the type of data that a variable can hold, such as
integers, floating-point numbers, characters, etc.
A: int is used for whole numbers (e.g., 10, -3), while float is used for numbers with
decimal points (e.g., 10.5, -3.14).
A: Signed data types can store both positive and negative values, whereas
unsigned data types can only store positive values.
A: The bool data type is used to store Boolean values, which are either true or
false.
A: The range of int depends on the system but is typically from -32768 to +32767
A: Yes, double has more precision and a larger range than float.
A: The void data type is used to indicate that a function does not return any value.
A: Yes, auto allows the compiler to automatically deduce the type of a variable
based on its initializer.
[2]
Experiments with Results and Viva-Voice Questions
Experiment
2
Number
WAP that calculates the Simple Interest and Compound
Experiment Title
Interest. The Principal, Amount, Rate of Interest and Time are
entered through the keyboard.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
#include<math.h>
void main() {
clrscr();
getch();
}
Input Enter the Principal amount: 1000
Enter the Rate of Interest: 2
Enter the Time (in years): 2
Output/Result
Simple Interest=P×R×T/100
Compound Interest=P(1+100/R)T−P
• Answer: The pow() function is used to raise the base(1+R to the power of
T (the time period), which is part of the Compound Interest formula.
• Answer: If the rate of interest is 0%, both the Simple Interest and
Compound Interest will be 0 because no interest will be applied.
9. Can the program handle negative values for Principal, Rate, or Time?
• Answer: The program does not handle negative input correctly. If the user
enters negative values, it will lead to incorrect results. The program should
10. How can the program be modified to calculate Compound Interest for
monthly compounding?
11. What is the expected output if the Principal is 1000, Rate is 5%, and Time
is 2 years?
• Answer: The program will display the Simple Interest and Compound
Interest based on the entered values. For example:
o Simple Interest = 100
o Compound Interest = 102.5
12. How does the program calculate the Compound Interest if the principal is
invested for multiple years?
• Answer: The program uses the formula for Compound Interest, which
calculates the total amount after the given time period by compounding the
interest annually, and then subtracts the principal to get the Compound
Interest.
13. What will happen if the user enters a decimal number for the principal,
rate, or time?
• Answer: The program can handle decimal numbers, and the calculation
will proceed correctly. For example, if the principal is 1000.50, the interest
will be calculated on the decimal value.
• Answer: The getch() function is used to wait for the user to press a key
before closing the program. It ensures that the output is visible to the user
until they acknowledge it by pressing any key.
[3]
Experiments with Results and Viva-Voce Questions
Experiment
3
Number
WAP to calculate the area and circumference of a circle.
Experiment Title
Experiment Input: The program asks for the radius of the circle.
Description Processing:
• The area of the circle is calculated using the formula:
Area=πr2
Circumference=2πr
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
#include<math.h>
void main() {
clrscr();
cout << "\nArea of the circle: " << area << endl;
cout << "Circumference of the circle: " << circumference <<
endl;
getch();
}
Input
Enter the radius of the circle: 5
Output/Result
Sample viva Q1. What is the formula used to calculate the area of the circle?
question Ans: The formula to calculate the area of the circle is Area=πr2
Q2. What is the formula used to calculate the circumference of the circle?
Q3 Why did you use the constant M_PI instead of defining Pi manually?
• Ans: The constant M_PI is defined in the math.h library, and it provides the
value of Pi. Using this built-in constant ensures better accuracy and
prevents hardcoding the value of Pi, which could lead to errors or
inconsistencies.
• Ans: The program does not handle negative input for the radius. If a
negative radius is entered, the program will calculate an invalid result.
Input validation could be added to check for valid positive radius values.
• Ans: The getch() function waits for the user to press any key before the
program terminates, allowing the user to view the output before the
window closes.
Q6 Can this program be used for other shapes, like squares or rectangles?
• Ans: No, this program is specifically designed for calculating the area and
circumference of a circle. Different formulas are required for other shapes,
such as squares or rectangles.
[4]
Experiments with Results and Viva-Voice Questions
Experiment 4
Number
Experiment Title WAP that accepts the temperature in Centigrade and converts
into Fahrenheit using the formula C/5=(F-32)/9
Course Design and develop algorithms using flowcharts, pseudo
Outcome(CO) code, and a selected programming language to solve
specificprogramming problems.
Hardwar Computer System with 2GB RAM and
e HardDisk storage
Tools/
Apparatus
Required Software Turbo C/C++ OR AN OTHER COMPILER
void main() {
float centigrade, fahrenheit;
clrscr();
cout << "Enter temperature in Centigrade: ";
cin >> centigrade;
getch();
}
Output/Result
• getch() is used to capture a key press from the user, which stops the
program from immediately closing. It waits for the user to press a key.
[5]
Experiments with Results and Viva-Voice Questions
Experiment
5
Number
WAP that swaps values of two variables using a third
Experiment Title
variable.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Experiment Initialization:
Description
• The two variables a and b are initialized with values 5 and
10, respectively.
Swapping Process:
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
void main() {
clrscr();
int a, b, temp;
temp = a;
a = b;
b = temp;
getch();
}
Output/Result
• The third variable temp is used to temporarily store one of the values so
that it is not overwritten during the swapping process. Without temp, we
would lose the value of one variable when assigning the value of the other.
4. What would happen if we didn't use the third variable temp in this
program?
• If we didn’t use the third variable temp, we would overwrite the value of a
when we assign b to a, and the original value of a would be lost. The swap
would not be correct.
• Yes, this can be done using arithmetic operations (e.g., addition and
subtraction) or XOR bitwise operation to swap values without a temporary
variable.
• First, the value of a is stored in the temporary variable temp. Then, the
value of b is assigned to a, and finally, the value stored in temp (which is
the original value of a) is assigned to b,
[6]
Experiments with Results and Viva-Voice Questions
Experiment
6
Number
WAP that checks whether the two numbers entered by the
Experiment Title
user are equal or not.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Comparison:
Output:
void main() {
clrscr(); .
int num1, num2;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
if (num1 == num2) {
cout << "The numbers are equal." << endl;
} else {
cout << "The numbers are not equal." << endl;
}
getch();
}
Sample viva 1 How does the program check if the two numbers are equal?
• The program uses an if statement to compare the two numbers. If num1
question == num2, it means the numbers are equal; otherwise, they are not equal.
2 What will happen if the user enters two identical numbers?
• If the user enters two identical numbers, the program will output that "The
numbers are equal."
3 What happens if the user enters two different numbers?
• If the user enters two different numbers, the program will output that "The
numbers are not equal."
• if-else statement
• else if ladder
• switch statement
A: The break statement prevents the execution from falling through to the next
case in the switch block.
A: Yes, relational operators like <, >, ==, !=, <=, >= can be used in an if condition.
A: No, the default case is optional, but it is good practice to include it to handle
unexpected values.
[7]
Experiments with Results and Viva-Voice Questions
Experiment
7
Number
WAP to find the greatest of three numbers.
Experiment Title
Experiment Input:
Description
• The program prompts the user to enter three integers
(num1, num2, and num3) using cin >> num1 >> num2 >>
num3;
Comparison Logic:
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
void main() {
clrscr();
getch();
}
Output/Result
Sample viva 1. How does the program compare the three numbers?
question • The program uses a series of if-else statements to compare the three
numbers. It checks if the first number is greater than or equal to the other
two, then checks the second number, and if neither is true, it assumes the
third number is the greatest.
• The program will display the number as the greatest, since all the numbers
are equal.
• The program uses the int data type to store the three numbers (num1,
num2, num3).
• The program will still work correctly and determine the greatest number,
whether positive or negative.
7. What is the output if the numbers entered are 5, 10, and 15?
• The output will be 15 is the greatest number.
• clrscr() clears the screen before the program starts, giving a clean display.
9. What will happen if the user enters the same value for all three numbers?
• The program will display that the entered number is the greatest, as all
values are equal.
[8]
Experiments with Results and Viva-Voice Questions
Experiment
8
Number
WAP that finds whether a given number is even or odd.
Experiment Title
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
void main() {
clrscr();
int num;
if (num % 2 == 0) {
cout << num << " is an Even Number.";
} else {
cout << num << " is an Odd Number.";
}
getch();
}
Output/Result
leaves a remainder of 1.
[9]
Experiments with Results and Viva-Voice Questions
Experiment
9
Number
WAP that tells whether a given year is a leap year or not.
Experiment Title
Experiment Input:
Description
• The program asks the user to enter a year using cin >>
year;.
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
void main() {
clrscr();
Vishal Chakradhari /24ADV3CST1183 Page | 29
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
int year;
getch();
}
Output/Result
[10]
Experiments with Results and Viva-Voice Questions
Experiment
10
Number
WAP that accepts marks of five subjects and finds percentage
Experiment Title
and prints grades.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Calculate Percentage:
Grade Assignment:
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
void main() {
clrscr();
else {
grade = 'F'; // Fail
}
getch();
}
[11]
Experiments with Results and Viva-Voice Questions
Experiment
11
Number
Write a program to calculate the sum of the elements of an
Experiment Title
array.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Experiment Input:
Description
• The program first asks the user to input the number of
elements for the array (n).
• Then, it takes the n elements from the user and stores
them in the array arr[].
Sum Calculation:
Experiment #include<iostream.h>
Code/ Procedure #include<conio.h>
void main() {
clrscr();
int n, sum = 0;
cout << "Enter the number of elements in the array: ";
cin >> n;
int arr[100];
getch();
}
Output/Result
Sample viva 1. How does the program calculate the sum of the array elements?
question • The program uses a for loop to iterate through each element of the array
and adds each element to a variable (sum).
• The clrscr() function is used to clear the screen before displaying any
output, making the program output look cleaner.
• The size of the array is dynamically defined based on the user input (n).
This ensures that the array size corresponds to the number of elements
the user wants to input.
4. What will happen if the user inputs a negative number for the size of the
array?
• If the user inputs a negative number for the array size, it will likely lead to
unpredictable behavior or errors, as array sizes cannot be negative.
• The cin statement is used to take input from the user. In this program, it is
used to input the number of elements and each element of the array.
6. What will the program output if the array elements are all zeros?
• If all the array elements are zeros, the sum will be zero.
• Yes, the program can handle negative numbers in the array. It will correctly
8. What happens if the user enters a value for n greater than the available
memory for the array?
• If the user enters a large value for n, it could lead to a memory overflow or
crash the program, especially in environments with limited memory.
• The getch() function pauses the program until the user presses a key. It
allows the user to see the result before the program closes.
for loop
while loop
A: A while loop checks the condition before executing the block, whereas a do-
while loop executes the block at least once before checking the condition.
A: An infinite loop is a loop that never terminates because the condition always
evaluates to true
A: Yes, it is possible
A: The continue statement skips the rest of the current iteration and moves to the
next iteration of the loop
[12]
Experiments with Results and Viva-Voice Questions
Experiment
12
Number
Create a program to manage a student database that stores
Experiment Title
their name, age, and grade.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
• The program first asks the user how many students they
want to enter. The numStudents variable holds this value.
Student Array:
Menu System:
Adding Students:
Display Students:
Experiment
Code/ Procedure #include <iostream.h>
#include <conio.h>
#include <string.h>
struct Student
{
char name[50];
int age;
char grade;
};
void main()
{
clrscr();
int numStudents;
cout << "Enter the number of students: ";
cin >> numStudents;
if (numStudents <= 0)
cout << "Invalid number of students!\n";
Student students[100];
int choice;
do {
clrscr();
cout << "\nStudent Database Menu:\n";
Vishal Chakradhari /24ADV3CST1183 Page | 42
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
switch (choice)
{
case 1:
for (int i = 0; i < numStudents; i++)
{
cout << "\nEnter details for student " << (i + 1)
<< ":\n";
cout << "Enter student's name: ";
cin>>students[i].name;
cout << "Enter student's age: ";
cin >> students[i].age;
cout << "Enter student's grade: ";
cin >> students[i].grade;
}
break;
case 2:
if (numStudents > 0)
{
for (int i = 0; i < numStudents; i++)
{
cout << "\nStudent " << (i + 1) << ":\n";
cout << "\n Name: " << students[i].name ;
cout << "\n Age: " << students[i].age ;
cout << "\n Grade: " << students[i].grade ;
}
} else {
cout << "No students in the database.\n";
}
getch();
break;
case 3:
cout << "Thank you for using Programme \n
Vishal Chakradhari /24ADV3CST1183 Page | 43
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
Exiting program...\n";
break;
default:
cout << "Invalid choice! Try again.\n";
}
} while (choice != 3);
getch();
}
Student 1:
Name: John Doe
Age: 20
Grade: B
Student 2:
Vishal Chakradhari /24ADV3CST1183 Page | 44
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
Exiting program...
Sample viva 1. What is the purpose of the clrscr() function in the program?
question • Answer: The clrscr() function is used to clear the screen in Turbo C++
IDE. It removes any previous output on the console before the program
displays new information.
• Answer: If cin.ignore() is not used, any leftover newline character (\n) from
the previous input would remain in the input buffer, which could cause
issues when using cin.getline() for reading strings, leading to skipping input
or incorrect behavior.
• Answer: The switch statement is used to present a menu and handle the
user’s choice. It allows the user to select from three options: adding
students, displaying student details, or exiting the program. Based on the
Vishal Chakradhari /24ADV3CST1183 Page | 45
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
• Answer: The do-while loop ensures that the menu is displayed at least
once, and it keeps running until the user chooses option 3 (Exit). The loop
continues to prompt for actions, providing the user with multiple
opportunities to perform actions like adding students or displaying details.
7. How would the program behave if the user enters an invalid number of
students (e.g., a negative number)?
• Answer: If the user enters a negative or zero value for numStudents, the
program will print "Invalid number of students!" and terminate immediately
due to the return statement, as the program cannot continue with invalid
input.
• Answer: The Student structure is used to store the data related to each
student, such as their name, age, and grade. It acts as a blueprint to
define the attributes of each student, allowing the program to manage and
organize the student data efficiently.
• Answer: The program does not use dynamic memory allocation (i.e., it
does not use new or delete). Instead, it uses a statically defined array of
Student objects, which means the memory for storing student data is pre-
allocated when the program runs. The memory size is fixed at 100
students in this case.
10. What would happen if the number of students entered exceeds 100?
• Answer: If the number of students entered exceeds 100, the program will
attempt to access memory outside of the array's bounds, which may cause
undefined behavior, memory corruption, or a crash. The program should
ideally handle this scenario, but in this version, it assumes that the user
won't exceed the fixed array size of 100.
struct Person {
string name;
int age;
float height;
Vishal Chakradhari /24ADV3CST1183 Page | 46
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
};
[13]
Experiments with Results and Viva-Voice Questions
Experiment
13
Number
WAP to check given string is a palindrome or not without
Experiment Title
using predefine function of string header file
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
Examples of Palindromes:
#include <string.h>:
strcpy(),
strrev(), and
int main()
{
char str[100], str1[100];
int k;
clrscr();
cout << "Enter a string: ";
cin >> str;
strcpy(str1,str);
strrev(str1);
if (strcmp(str, str1) == 0)
{
cout << "The string is a palindrome." << endl;
}
else
{
Vishal Chakradhari /24ADV3CST1183 Page | 49
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
getch();
}
Input
Enter a string: madam
Output/Result
Answer: It includes the input/output stream functions like cin, cout, endl, and other
standard I/O operations.
Answer: It includes the console input/output functions like clrscr() (to clear the
screen) and getch() (to wait for user input before closing the program).
Answer: The clrscr() function clears the console screen (only available in older
compilers like Turbo C++).
Answer: It takes input from the user and stores the string in the character array str.
Answer: The strcpy() function copies the content of the string str into str1.
Answer: The strcmp() function compares two strings (str and str1). It returns 0 if the
strings are identical, indicating that the string is a palindrome.
Answer: This condition checks if the original string str is the same as the reversed
string str1. If true, it confirms that the string is a palindrome.
Answer: The output will be "The string is not a palindrome." because "hello" is not
the same when reversed.
Answer: The getch() function waits for the user to press any key before closing the
program window. It is used to pause the execution in console-based applications.
[14]
Experiments with Results and Viva-Voice Questions
Experiment
14
Number
Write a program that calculates the average of a list of
Experiment Title
numbers using functions.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
void main() {
clrscr();
int n;
cout << "Enter the number of elements: ";
cin >> n;
int numbers[100];
cout << "The average of the entered numbers is: " << avg <<
endl;
getch();
}
Output/Result
• Call by value: The actual value of the argument is passed to the function,
so changes made inside the function do not affect the original variable.
• Call by reference: A reference (memory address) to the original variable
is passed to the function, so changes made inside the function affect the
original variable.
• The return type is float because the average could be a decimal number,
and using float allows the program to return decimal values.
3. What is the significance of the int arr[] and int size parameters in the
calculateAverage function?
• int arr[] is an array that holds the numbers entered by the user, and int size
is the number of elements in the array. These two parameters allow the
function to process the correct number of elements to calculate the
average.
A function is a block of code that performs a specific task and can be reused
multiple times.
returnType functionName(parameters) {
Q Built-in functions: Provided by the C++ Standard Library (e.g., sqrt, abs).
The return type specifies the type of value the function returns (e.g., int, float, void).
By writing the function name followed by parentheses with arguments (if required).
Example:
Declaration: Provides the function’s name, return type, and parameters without the
body.
return a + b;
[15]
Experiments with Results and Viva-Voice Questions
Experiment
15
Number
Write a program that uses functions to perform mathematical
Experiment Title
operations and demonstrate the concepts of call by value, call
by reference, and recursive functions.
Demonstrate an understanding of computer systems and their
Course Outcome
components, including memory, processor, I/O devices,
(CO)
storage, and operating systems
Computer System with 2GB RAM and Hard Disk
Hardware
storage
Tools/Apparatus
Required
Software Turbo C/C++ OR AN OTHER COMPILER
int factorial(int n) {
if (n == 0) {
return 1; // Base case
} else {
return n * factorial(n - 1);
}
}
void main() {
clrscr();
cout << "Enter two numbers for addition (Call by value): ";
cin >> num1 >> num2;
cout << "Sum of " << num1 << " and " << num2 << " is: " <<
addByValue(num1, num2) << endl;
cout << "Enter two numbers for swapping (Call by reference): ";
cin >> num1 >> num2;
cout << "Before swapping: num1 = " << num1 << ", num2 =
Vishal Chakradhari /24ADV3CST1183 Page | 57
IAC-Core, SAGE University Indore B.Tech . - CST I-Sem
subtractByReference(num1, num2);
cout << "After swapping: num1 = " << num1 << ", num2 = "
<< num2 << endl;
int num;
cout << "Enter a number to calculate its factorial (Recursive
function): ";
cout << "Factorial of " << num << " is: " << factorial(num)
<< endl;
getch();
}
Output/Result