Lab CSE 304-01
Lab CSE 304-01
Report title: Implementation of adding two numbers using user define function in C++
programming language.
IDE: Visual Studio Code.
Algorithm: Algorithm of adding two numbers using user define function is given below:
Step-1: start
Step-2: Declare two integer variables a and b.
Step-3: Define a function add(int x, int y) that takes two integer parameters and returns their
sum.
• Prompt the user to enter the first number and store the input in variable a.
• Prompt the user to enter the second number and store the input in variable b.
Step-4: Call the add() function by passing the values of a and b, and store the result.
Step-5: Display the sum of the two numbers.
Step-6: End the program.
Pseudocode:
1. Start
2. Define a function add(x, y) that returns x + y
3. Input the first number and store it in a
4. Input the second number and store it in b
5. Call the function add(a, b) and store the result in result
6. Print the result
7. End
Source code:
#include<bits/stdc++.h>
using namespace std;
cout << "Sum of " << a << " and " << b << " is " << add(a, b) << endl;
return 0;
}
Conclusion:
In this lab report, we successfully implemented a program in C++ to add two numbers using a
user-defined function. The program effectively takes input from the user, processes the data
through a function, and displays the result. By using functions, we were able to make the code
more modular and reusable, which is a key concept in programming. This lab helped in
understanding the use of functions, user input handling, and the basic structure of a C++
program. Overall, the experiment enhanced our knowledge of function implementation and
basic C++ syntax.