From 8db5358a82bc4e631ac8b672f1507cf492b64c63 Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:29:00 +0530 Subject: [PATCH 1/9] Update for-loop.md Updated loop --- docs/day-05/for-loop.md | 88 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 5 deletions(-) diff --git a/docs/day-05/for-loop.md b/docs/day-05/for-loop.md index 0c0f2fd01..a0abf2c77 100644 --- a/docs/day-05/for-loop.md +++ b/docs/day-05/for-loop.md @@ -8,11 +8,89 @@ slug: for-loop-in-cpp TASK: -1. What is the For Loop in C++? -2. Explain the Syntax of For Loop in C++. -3. C++ for Loop Example -4. C++ Infinite for Loop -5. C++ Nested for Loop + ## 1. What is the For Loop in C++? +A For loop is a repetition control structure that allows us to write a loop that is executed a specific number of times. The loop enables us to perform n number of steps together in one line. + +### Syntax: +```cpp +for (initialization expr; test expr; update expr) +{ + // body of the loop + // statements we want to execute +} +``` IMAGE FILE: ![For Loop](../../static/img/day-05/for-loop-in-cpp.png) + +## 2. Explain the Syntax of For Loop in C++. + +### Syntax: +```cpp +for (initialization expr; test expr; update expr) +{ + // body of the loop + // statements we want to execute +} +Here, + +Initialization – this expression initializes variable(s) and is executed only once. + +Condition – if the specified test condition is True, the body of the for loop is executed. In case the test condition returns False, the for loop is terminated. + +Update – this expression updates the value of initialized variables and then the condition is evaluated again. +``` +## 3. C++ for Loop Example + +The program uses a for loop to print "Hello World!" five times to the console. + +## Example +```cpp + +#include + +using namespace std; + +int main() { + for (int i = 1; i <= 5; ++i) { + cout << i << " "; + } + return 0; +} +``` + +## 4. C++ Infinite for Loop + +The program uses a for loop without any conditions, which creates an infinite loop that continuously prints "This loop will run forever." to the console. + +## Example +```cpp +#include + +using namespace std; + +int main() { + for (;;) { + cout << "This loop will run forever." << endl; + } + return 0; +} + +``` +## 5. C++ Nested for Loop +The program uses nested for loops to iterate through values of i from 1 to 3 and j from 1 to 2, printing each combination to the console. + +## Example +```cpp +#include + +using namespace std; + +int main() { + for (int i = 1; i <= 3; ++i) { + for (int j = 1; j <= 2; ++j) { + cout << "i = " << i << ", j = " << j << endl; + } + } + return 0; +} From ba98aca49e14c7454f38ac2e63c8a8fbdd1bb08d Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:30:21 +0530 Subject: [PATCH 2/9] Update for-loop.md updated --- docs/day-05/for-loop.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/day-05/for-loop.md b/docs/day-05/for-loop.md index a0abf2c77..455569b4b 100644 --- a/docs/day-05/for-loop.md +++ b/docs/day-05/for-loop.md @@ -32,6 +32,7 @@ for (initialization expr; test expr; update expr) // body of the loop // statements we want to execute } +``` Here, Initialization – this expression initializes variable(s) and is executed only once. @@ -39,7 +40,7 @@ Initialization – this expression initializes variable(s) and is executed only Condition – if the specified test condition is True, the body of the for loop is executed. In case the test condition returns False, the for loop is terminated. Update – this expression updates the value of initialized variables and then the condition is evaluated again. -``` + ## 3. C++ for Loop Example The program uses a for loop to print "Hello World!" five times to the console. From e600d548c03771c0cbf0847effa1d2be9e856baf Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:32:08 +0530 Subject: [PATCH 3/9] Update if-else-statement.md updated --- docs/day-05/if-else-statement.md | 135 ++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 13 deletions(-) diff --git a/docs/day-05/if-else-statement.md b/docs/day-05/if-else-statement.md index 1733ed286..dbac04376 100644 --- a/docs/day-05/if-else-statement.md +++ b/docs/day-05/if-else-statement.md @@ -6,16 +6,125 @@ sidebar_label: "IF-ELSE Statement" slug: if-else-statement-in-cpp --- -TASK: - -1. What is Control Statements in C++? -2. What is the IF-ELSE Statement in C++? -3. Explain the Syntax of IF-ELSE Statement in C++. -4. C++ if Statement -5. C++ if-else Statement -6. C++ Nested if-else Statement -7. C++ if-else-if Ladder -8. C++ Ternary Operator - -IMAGE FILE: -![if else in cpp](../../static/img/day-05/if-else-statement.png) \ No newline at end of file +## 1. What is Control Statements in C++? +Control statements are the keywords and judgement makers of C++, which controls the run time process of a program. These statements enable the program to decide on a course of action, to compute repetitive tasks and to determine the program’s flow according to specific conditions that may have been defined in the statements. There are two primary types of control statements in C++: + - Conditionals + - Loops + +**Conditional Statements** +Conditional Statements are block of statements used to execute code based on a certain condition. +There are two types: `if-else` and `Switch` statements. + +**Loop Statements** +Loop statements are used to repeat certain task or a block of code. +Types are: `for`, `while` and `do-while` Loops. + + +![if else in cpp](../../static/img/day-05/if-else-statement.png) + + +## 2. What is the IF-ELSE Statement in C++? +The IF-ELSE statement in C++ is a conditional statement that executes different code blocks based on whether a given condition is `true` or `false`. This is a fundamental concept in programming that allows for decision-making and branching in the code. + +### Syntax + +```cpp +if (condition) { + // Code to execute if condition is true +} else { + // Code to execute if condition is false +} +``` + +## 3. C++ if Statement +The simplest form of the conditional statement that executes a block of code if the condition is `true`. + +### Example +```cpp +#include +using namespace std; + +int main(){ + int x = 10; + + if(x > 5){ + cout<<"the number is greater than 5"< +using namespace std; + +int main(){ + int x = 10; + + if (x > 15) { + cout << "x is greater than 15"; + } else { + cout << "x is not greater than 15"; + } +} +``` + +## 5. C++ Nested if-else Statement +You can also nest if-else statements inside another if or else block to create more complex conditions. + +### Example +```cpp +#include +using namespace std; + +int main(){ + int x = 10; + int y = 20; + if (x > 5) { + if (y > 15) { + cout << "x is greater than 5 and y is greater than 15"; + } else { + cout << "x is greater than 5 but y is not greater than 15"; + } + } else { + cout << "x is not greater than 5"; + } +} +``` +## 6. C++ if-else-if Ladder +This is used when you have multiple conditions to evaluate. Each condition is checked in sequence, and the block of code for the first true condition is executed. + +### Example +```cpp +#include +using namespace std; + +int main(){ + int x = 10; + if (x == 10) { + cout << "x is 10"; + } else if (x == 20) { + cout << "x is 20"; + } else if (x == 30) { + cout << "x is 30"; + } else { + cout << "x is not 10, 20, or 30"; + } +} + +``` +## 7. C++ Ternary Operator +The ternary operator is a shorthand way to write simple if-else statements. It is also known as the conditional operator. + +### Example +```cpp +#include +using namespace std; + +int main(){ + int x = 10; + string result = (x > 5) ? "x is greater than 5" : "x is not greater than 5"; + cout << result; +} From bcfd858e22dda0690d15e1419b667ac598a11f0a Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:44:44 +0530 Subject: [PATCH 4/9] Create Whileloop.png --- static/img/day-05/Whileloop.png | 1 + 1 file changed, 1 insertion(+) create mode 100644 static/img/day-05/Whileloop.png diff --git a/static/img/day-05/Whileloop.png b/static/img/day-05/Whileloop.png new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/static/img/day-05/Whileloop.png @@ -0,0 +1 @@ + From 15cc555f878a53e0d7edecdd3ab43d8f31635247 Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:55:12 +0530 Subject: [PATCH 5/9] Update do-while-loop.md updated --- docs/day-05/do-while-loop.md | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/docs/day-05/do-while-loop.md b/docs/day-05/do-while-loop.md index 204a21bf4..927c3f205 100644 --- a/docs/day-05/do-while-loop.md +++ b/docs/day-05/do-while-loop.md @@ -16,5 +16,75 @@ TASK: 6. Flowchart of do...while Loop 7. Example 2: Display Numbers from 1 to 5 +IMAGE FILE: +![Do While Loop](../../static/img/day-05/while-do-while-loop-in-cpp.png)TASK: + +## 1. C++ while and do...while Loop + +The `while`loop loops through a block of code as long as a specified condition is true: + +The `do/while` loop is a variant of the `while` loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. + IMAGE FILE: ![Do While Loop](../../static/img/day-05/while-do-while-loop-in-cpp.png) + +## 2. C++ while Loop + +The `while`loop loops through a block of code as long as a specified condition is true: + +### Syntax +```cpp +while (condition) { + // code block to be executed +} + +``` + +## 3. Example 1: Display Numbers from 1 to 5 + +The program uses a while loop to print numbers from 1 to 5 to the console. +```cpp +#include + +using namespace std; + +int main() { + int i = 1; + while (i <= 5) { + cout << i << endl; + ++i; + } + return 0; +} + +``` +## 4. C++ do...while Loop + +The `do/while` loop is a variant of the `while` loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. + +### Syntax +```cpp +do { + // code block to be executed +} +while (condition); +``` + +## 5. Example 2: Display Numbers from 1 to 5 + +The program uses a do-while loop to print numbers from 1 to 5 to the console. + +```cpp +#include + +using namespace std; + +int main() { + int i = 1; + do { + cout << i << endl; + ++i; + } while (i <= 5); + return 0; +} +``` From e80b2d7809cdf342bff6723bff644b1394be95b3 Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:55:52 +0530 Subject: [PATCH 6/9] Update do-while-loop.md update --- docs/day-05/do-while-loop.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/docs/day-05/do-while-loop.md b/docs/day-05/do-while-loop.md index 927c3f205..ae18bce61 100644 --- a/docs/day-05/do-while-loop.md +++ b/docs/day-05/do-while-loop.md @@ -6,19 +6,6 @@ sidebar_label: "While and Do-While Loop" slug: while-and-do-while-loop-in-cpp --- -TASK: - -1. C++ while and do...while Loop -2. C++ while Loop -3. Flowchart of while Loop -4. Example 1: Display Numbers from 1 to 5 -5. C++ do...while Loop -6. Flowchart of do...while Loop -7. Example 2: Display Numbers from 1 to 5 - -IMAGE FILE: -![Do While Loop](../../static/img/day-05/while-do-while-loop-in-cpp.png)TASK: - ## 1. C++ while and do...while Loop The `while`loop loops through a block of code as long as a specified condition is true: From 4f81f833d80c170d9762e05716c8b5fd1a45a334 Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:03:01 +0530 Subject: [PATCH 7/9] Update if-else-statement.md u --- docs/day-05/if-else-statement.md | 121 ------------------------------- 1 file changed, 121 deletions(-) diff --git a/docs/day-05/if-else-statement.md b/docs/day-05/if-else-statement.md index dbac04376..8f119c564 100644 --- a/docs/day-05/if-else-statement.md +++ b/docs/day-05/if-else-statement.md @@ -6,125 +6,4 @@ sidebar_label: "IF-ELSE Statement" slug: if-else-statement-in-cpp --- -## 1. What is Control Statements in C++? -Control statements are the keywords and judgement makers of C++, which controls the run time process of a program. These statements enable the program to decide on a course of action, to compute repetitive tasks and to determine the program’s flow according to specific conditions that may have been defined in the statements. There are two primary types of control statements in C++: - - Conditionals - - Loops -**Conditional Statements** -Conditional Statements are block of statements used to execute code based on a certain condition. -There are two types: `if-else` and `Switch` statements. - -**Loop Statements** -Loop statements are used to repeat certain task or a block of code. -Types are: `for`, `while` and `do-while` Loops. - - -![if else in cpp](../../static/img/day-05/if-else-statement.png) - - -## 2. What is the IF-ELSE Statement in C++? -The IF-ELSE statement in C++ is a conditional statement that executes different code blocks based on whether a given condition is `true` or `false`. This is a fundamental concept in programming that allows for decision-making and branching in the code. - -### Syntax - -```cpp -if (condition) { - // Code to execute if condition is true -} else { - // Code to execute if condition is false -} -``` - -## 3. C++ if Statement -The simplest form of the conditional statement that executes a block of code if the condition is `true`. - -### Example -```cpp -#include -using namespace std; - -int main(){ - int x = 10; - - if(x > 5){ - cout<<"the number is greater than 5"< -using namespace std; - -int main(){ - int x = 10; - - if (x > 15) { - cout << "x is greater than 15"; - } else { - cout << "x is not greater than 15"; - } -} -``` - -## 5. C++ Nested if-else Statement -You can also nest if-else statements inside another if or else block to create more complex conditions. - -### Example -```cpp -#include -using namespace std; - -int main(){ - int x = 10; - int y = 20; - if (x > 5) { - if (y > 15) { - cout << "x is greater than 5 and y is greater than 15"; - } else { - cout << "x is greater than 5 but y is not greater than 15"; - } - } else { - cout << "x is not greater than 5"; - } -} -``` -## 6. C++ if-else-if Ladder -This is used when you have multiple conditions to evaluate. Each condition is checked in sequence, and the block of code for the first true condition is executed. - -### Example -```cpp -#include -using namespace std; - -int main(){ - int x = 10; - if (x == 10) { - cout << "x is 10"; - } else if (x == 20) { - cout << "x is 20"; - } else if (x == 30) { - cout << "x is 30"; - } else { - cout << "x is not 10, 20, or 30"; - } -} - -``` -## 7. C++ Ternary Operator -The ternary operator is a shorthand way to write simple if-else statements. It is also known as the conditional operator. - -### Example -```cpp -#include -using namespace std; - -int main(){ - int x = 10; - string result = (x > 5) ? "x is greater than 5" : "x is not greater than 5"; - cout << result; -} From a9d7a5c7939d63d79652a932604f89917a262f28 Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:05:31 +0530 Subject: [PATCH 8/9] Delete docs/day-05/if-else-statement.md y --- docs/day-05/if-else-statement.md | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 docs/day-05/if-else-statement.md diff --git a/docs/day-05/if-else-statement.md b/docs/day-05/if-else-statement.md deleted file mode 100644 index 8f119c564..000000000 --- a/docs/day-05/if-else-statement.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -sidebar_position: 1 -title: "IF-ELSE Statement in C++" -description: "The if...else statement is used to run one block of code under certain conditions and another block of code under different conditions. In this tutorial, we will learn C++ if, if…else and nested if…else with the help of examples.." -sidebar_label: "IF-ELSE Statement" -slug: if-else-statement-in-cpp ---- - - From e1fb19ab4d6315c3fa5241ce69ac28165538fe8e Mon Sep 17 00:00:00 2001 From: Sahil Vaidya <131428615+Sahil-Vaidya@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:07:47 +0530 Subject: [PATCH 9/9] Update function-in-cpp.md updatedd --- docs/day-07/function-in-cpp.md | 377 +++++++++++++++++++++++++++++++-- 1 file changed, 363 insertions(+), 14 deletions(-) diff --git a/docs/day-07/function-in-cpp.md b/docs/day-07/function-in-cpp.md index 6de2375b6..07717d53c 100644 --- a/docs/day-07/function-in-cpp.md +++ b/docs/day-07/function-in-cpp.md @@ -6,21 +6,370 @@ sidebar_label: "Function" slug: function-in-cpp --- -TASK: - -1. What is a Function in C++? -2. Explain the Syntax of Function in C++. -3. Types of Functions in C++ -4. How to Declare and Define a Function in C++? -5. How to Call a Function in C++? -6. C++ Function Example -7. C++ Function with Parameters -8. C++ Function with Return Value -9. C++ Function with Default Arguments -10. C++ Function with Function Overloading -11. C++ Function with Recursion -12. C++ Function with Inline Function +### 1. What is a Function in C++? +A Function in c++ is a block of code that perform specific task and can be called by its name, optionally taking input parameters and returning a value. Functions help in modularizing code, making it reusable and easier to manage. IMAGE FILE: ![Function in CPP](../../static/img/day-07/function-in-cpp.png) + +### 2. Explain the Syntax of Function in C++. + +### Syntax +```cpp +void myFunction() { + // code to be executed +} +``` +## Explaination + + myFunction() is the name of the function. + void means that the function does not have a return value. You will learn more about return values later in the next chapter. + inside the function (the body), add code that defines what the function should do. + +### 3. Types of Functions in C++ + +## Built-in Functions +Built-in functions are also called library functions. These are the functions that are provided by C++ and we need not write them ourselves. We can directly use these functions in our code. + +## User-Defined Functions +C++ also allows its users to define their own functions. These are the user-defined functions. We can define the functions anywhere in the program and then call these functions from any part of the code. + +### 4. How to Declare and Define a Function in C++? + +In C++, declaring and defining a function involves two main steps: the function declaration (also known as the function prototype) and the function definition. + +## Function Declaration +A function declaration specifies the function's name, return type, and parameters without including the function body. It informs the compiler about the function's existence before its actual definition. + +### Syntax +```cpp +returnType functionName(parameterType1 parameterName1, parameterType2 parameterName2, ...); + +``` +## Example +```cpp +int add(int a, int b); +``` +## Function Definition +A function definition includes the function's body, which contains the actual code that will be executed when the function is called. + +### Syntax +```cpp +returnType functionName(parameterType1 parameterName1, parameterType2 parameterName2, ...) { + // Function body: code to be executed +} +``` +## Example +```cpp +#include + +using namespace std; + +// Function definition +int add(int a, int b) { + return a + b; +} + +``` +## Output + 7 + +### 5. How to Call a Function in C++? + +Calling a function in C++ involves using the function name followed by parentheses containing any necessary arguments. + +### Syntax +```cpp +functionName(argument1, argument2, ...); +``` +## Example +```cpp +#include + +using namespace std; +// Function declaration (prototype) +int add(int a, int b); + +int main() { + int num1 = 3; + int num2 = 4; + + // Function call + int result = add(num1, num2); + + // Display the result + cout << "The sum is: " << result << endl; + + return 0; +} +``` +## Output + 7 +### 6. C++ Function Example + +This example calculates the factorial of a given number. + +## Example +```cpp +#include + +using namespace std; + +// Function declaration (prototype) +int factorial(int n); + +int main() { + int number; + cout << "Enter a positive integer: "; + cin >> number; + + // Function call + int result = factorial(number); + + // Display the result + cout << "Factorial of " << number << " = " << result << endl; + + return 0; +} + +// Function definition +int factorial(int n) { + if (n == 0 || n == 1) + return 1; + else + return n * factorial(n - 1); +} + +``` +### 7. C++ Function with Parameters + +Information can be passed to functions as a parameter. Parameters act as variables inside the function. + +### Syntax +```cpp +void functionName(parameter1, parameter2, parameter3) { + // code to be executed +} +``` +## Example : In this example, the function calculates and returns the area of a rectangle using its length and width as parameters. +```cpp +#include + +using namespace std; + +// Function declaration (prototype) +double calculateArea(double length, double width); + +int main() { + double length, width; + + // Input length and width from the user + cout << "Enter length of the rectangle: "; + cin >> length; + cout << "Enter width of the rectangle: "; + cin >> width; + + // Function call + double area = calculateArea(length, width); + + // Display the area + cout << "Area of the rectangle: " << area << endl; + + return 0; +} + +// Function definition +double calculateArea(double length, double width) { + return length * width; +} + +``` +### 8. C++ Function with Return Value + +The return statement returns the flow of the execution to the `function` from where it is called. + +### Syntax +```cpp +return[expression]; +``` +## Example : function that calculates the sum of two integers and returns the result: +```cpp +#include + +using namespace std; + +// Function declaration (prototype) +int sum(int a, int b); + +int main() { + int num1, num2; + + // Input two numbers from the user + cout << "Enter first number: "; + cin >> num1; + cout << "Enter second number: "; + cin >> num2; + + // Function call + int result = sum(num1, num2); + + // Display the result + cout << "Sum: " << result << endl; + + return 0; +} + +// Function definition +int sum(int a, int b) { + return a + b; +} + +``` +### 9. C++ Function with Default Arguments + +A default argument is a value provided in a function declaration that is automatically assigned by the compiler if the calling function doesn’t provide a value for the argument. In case any value is passed, the default value is overridden. + +## Example : +```cpp +#include +using namespace std; + +int sum(int x, int y, int z = 0, int w = 0) //assigning default values to z,w as 0 +{ + return (x + y + z + w); +} + +// Driver Code +int main() +{ + // Statement 1 + cout << sum(10, 15) << endl; + + // Statement 2 + cout << sum(10, 15, 25) << endl; + + // Statement 3 + cout << sum(10, 15, 25, 30) << endl; + return 0; +} +``` +## Output + 25 + 50 + 80 + +### 10. C++ Function with Function Overloading + +Function overloading is a feature of object-oriented programming where two or more functions can have the same name but different parameters. When a function name is overloaded with different jobs it is called Function Overloading. In Function Overloading “Function” name should be the same and the arguments should be different. + +## Example +```cpp +#include +using namespace std; + + +void add(int a, int b) +{ +cout << "sum = " << (a + b); +} + +void add(double a, double b) +{ + cout << endl << "sum = " << (a + b); +} + +// Driver code +int main() +{ + add(10, 2); + add(5.3, 6.2); + + return 0; +} +``` +## Output +sum = 12 +sum = 11.5 + +### 11. C++ Function with Recursion + +Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are easier to solve. + +##Example : function that demonstrates recursion by calculating the factorial of a given number: +```cpp +#include + +using namespace std; + +// Function declaration +int factorial(int n); + +int main() { + int number; + + // Input a number from the user + cout << "Enter a non-negative integer: "; + cin >> number; + + // Call the factorial function + int result = factorial(number); + + // Display the result + cout << "Factorial of " << number << " = " << result << endl; + + return 0; +} + +// Function definition +int factorial(int n) { + // Base case: factorial of 0 or 1 is 1 + if (n == 0 || n == 1) { + return 1; + } + // Recursive case: factorial of n is n multiplied by factorial of (n-1) + else { + return n * factorial(n - 1); + } +} + +``` +### 12. C++ Function with Inline Function + +C++ provides inline functions to reduce the function call overhead. An inline function is a function that is expanded in line when it is called. When the inline function is called whole code of the inline function gets inserted or substituted at the point of the inline function call. + +## Syntax: + +inline return-type function-name(parameters) +{ + // function code +} + +## Example : In this example, we'll create an inline function to calculate the square of a number. +```cpp +#include + +using namespace std; + +// Inline function declaration +inline int square(int x) { + return x * x; +} + +int main() { + int num; + + // Input a number from the user + cout << "Enter a number: "; + cin >> num; + + // Call the inline function + int result = square(num); + + // Display the result + cout << "Square of " << num << " = " << result << endl; + + return 0; +} + +```