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

Fuction

function in cpp program how
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Fuction

function in cpp program how
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream> // Include input/output library

using namespace std; // Use the standard namespace

// Function to add two numbers


int addNumbers(int a, int b) {
return a + b;
}

int main() {
int num1, num2, sum;

// Ask for input from the user


cout << "Enter first number: ";
cin >> num1; // Read the first number

cout << "Enter second number: ";


cin >> num2; // Read the second number

// Call the addNumbers function and store the result in sum


sum = addNumbers(num1, num2);

// Output the result


cout << "The sum of " << num1 << " and " << num2 << " is: " << sum << endl;

return 0; // End of program


}

#include <iostream> // Include input/output library


using namespace std; // Use the standard namespace

// Void function to print the sum of two numbers


void printSum(int a, int b) {
int sum = a + b; // Calculate the sum
cout << "The sum of " << a << " and " << b << " is: " << sum << endl;
}

int main() {
int num1, num2;

// Ask for input from the user


cout << "Enter first number: ";
cin >> num1; // Read the first number

cout << "Enter second number: ";


cin >> num2; // Read the second number

// Call the void function to print the sum


printSum(num1, num2);

return 0; // End of program


}

You might also like