This code prompts the user to input two integers, passes them to a function named add, and then displays the result of adding those two integers. The add function takes two integers as parameters, adds them together, and then displays the result. Overall, this code demonstrates how to define and call a simple function in C++.
#include<iostream> using namespace std; void add(int,int); int main() { int a,b; cout<<"\nEnter The Two Values:"; cin>>a>>b; add(a,b); return 0; } void add(int a,int b) { int c; c=a+b; cout<<"\nAddition:"<<c; }To download raw file Click Here
Enter The Two Values:45 67 Addition:112
This program defines a function called add which takes two integer inputs from the user, adds them together, and prints out the result. The add function is declared before main using the function prototype void add();, which tells the compiler that there is a function called add that takes no arguments and returns nothing.
In the main function, the add function is called using add();, which executes the code inside the function definition. Inside the add function, two integers are read in using cin, added together, and the result is printed out using cout. Overall, this program is a simple example of how to define and call a function in C++.
#include<iostream> using namespace std; void add();//Function Declaration int main() { add();//Function Calling return 0; } void add()//Function Definition { int a,b,c; cout<<"\nEnter The Two values:"; cin>>a>>b; c=a+b; cout<<"Addition:"<<c; }To download raw file Click Here
Enter The Two values:56 53 Addition:59
This program defines a function called myFunction that takes a string argument fname and outputs a message with the given fname concatenated with the string "Kumar". Then, the function is called three times with different names ("Arun", "Ram", and "Aswin") as arguments.
#include<iostream> using namespace std; void myFunction(string fname) { cout<<fname<<"Kumar\n"; } int main() { myFunction("Arun"); myFunction("Ram"); myFunction("Aswin"); return 0; }To download raw file Click Here
ArunKumar RamKumar AswinKumar
This program demonstrates the use of a function to perform addition of two integers. The function add takes two integer arguments a and b and returns their sum as an integer. In the main function, the user is prompted to input two integers a and b, which are passed as arguments to the function add. The result of the addition is then printed to the console.
#include<iostream> using namespace std; int add(int,int); int main() { int a,b; cout<<"\nEnter The Two Values:"; cin>>a>>b; cout<<"\nAddition:"<<add(a,b); return 0; } int add(int a,int b) { int c; c=a+b; return c; }To download raw file Click Here
Enter The Two Values:56 43 Addition:99
This program demonstrates the use of a function to perform addition of two numbers. The program defines a function called add() that takes two integer inputs from the user and returns their sum. In the main function, the add() function is called and its return value is printed to the console.
The program starts by including the iostream header file, which provides the input/output functionality. Then, the add() function is declared with a return type of int and no arguments. In the main function, the add() function is called using the cout statement, which prints the result of the function to the console. Finally, the main function returns 0, indicating successful execution of the program.
#include<iostream> using namespace std; int add(); int main() { cout<<"\nAddition:"<<add(); return 0; } int add() { int a,b,c; cout<<"\nEnter The Two Values:"; cin>>a>>b; c=a+b; return c; }To download raw file Click Here
Addition: Enter The Two Values:56 65 121
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions