0% found this document useful (0 votes)
17 views2 pages

Lab CSE 304-01

The report details the implementation of a C++ program that adds two numbers using a user-defined function. It includes an algorithm, pseudocode, and source code, demonstrating user input handling and function usage. The conclusion emphasizes the modularity and reusability of code through functions, enhancing understanding of C++ programming concepts.

Uploaded by

mecaf52858
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)
17 views2 pages

Lab CSE 304-01

The report details the implementation of a C++ program that adds two numbers using a user-defined function. It includes an algorithm, pseudocode, and source code, demonstrating user input handling and function usage. The conclusion emphasizes the modularity and reusability of code through functions, enhancing understanding of C++ programming concepts.

Uploaded by

mecaf52858
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/ 2

Dhaka International University

Department of Computer Science and Engineering


Report no: 01 Date of submission: 30 January, 2025

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;

int add(int x, int y){


return x+y;
}
int main(){
int a, b;
cout << "Enter first number: ";
cin >> a;
cout << "Enter second number: ";
cin >> b;

cout << "Sum of " << a << " and " << b << " is " << add(a, b) << endl;
return 0;
}

1 | Page Batch no:D-80 (1st Shift) Roll No: 30


Dhaka International University
Department of Computer Science and Engineering

Output: Output of the program is given below:

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.

2 | Page Batch no:D-80 (1st Shift) Roll No: 30

You might also like