Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ function

#include<iostream>
using namespace std;

void square(int value)
{
	int total = pow(value, 2);
	cout << total << endl;
}

void cube(int value)
{
	int total = pow(value, 3);
	cout << total << endl;
}

int main()
{
	int value;
	cout << "Enter value: ";
	cin >> value;

	if (value % 2 == 0)
	{
		square(value);
	}
	else
	{
		cube(value);
	}

	return 0;
}
Comment

function c++

#include <iostream>
using namespace std;
// Input a,b
// Output Combination a!/b!(a-b)!
	int fac(int x){
	int s=1;
	for(int i=x;i>0;i--){
		s*=i;
	}
	return s;
	}
	int con (int x,int y){
	int c;
	c=fac(x)/(fac(y)*fac(x-y));
	return c;
	}
	int main(){
	int a,b;
	cout<<"Enter the first number : ";
	cin >> a;
	cout<<"Enter the second number : ";
	cin >> b;
	cout<<"The conbination of these number : ";
	cout<<con(a,b);
	return 0;
	}
Comment

function in c++

#include <iostream>

using namespace std;

void function(){
    cout << "I am a function!" << endl;
}

int main()
{
    function();

    return 0;
}
Comment

c++ function

// the void function
void function() {
 cout << "Hello World!";
}

// the main function
int main() {
 function();
 return 0;
}
Comment

functions in C++

void Hello() {
  std::cout << "Hello";
}

int main () {
  Hello();
}
Comment

cpp define function

//INCLUDING BUILT-IN LIBRARIES...
#include <iostream>
#include <stdlib.h>
//PRE-DEFINE CONSTANT VALUES...
#define MAXNUM -12    //defining an integer
#define PI 3.1415     //defining a float
#define END "

		Program has ended!!
"   //defining a string
//PRE-DEFINING CONSTANT OPERATIONS...
#define ADD(a, b, c) (a + b + c)    //Operation that will add its 3 parameters

using namespace std;

int main(){
    //using other definitions to check if the current device is Windows or UNIX
    #ifdef _WIN32  
        cout<<"Windows Operating System Detected"<<endl;
    #elif __unix__
        cout<<"UNIX Operating System Detected"<<endl;
    #else
        cout<<"Operating System could NOT be identified!"<<endl;
    #endif
    
    cout<<endl<<"Using pre-defined values and operations: "<<endl;
    cout<<" • MAXNUM: "<<MAXNUM<<endl;       //using pre-defined integer
    cout<<" • PI: "<<PI<<endl;               //using pre-defined float
    cout<<" • ADD(): "<<ADD(2,5,99.5)<<endl;   //using pre-defined function

    cout<<END;    //using pre-defined string
    return 0;
}
Comment

define in cpp

#include <iostream> 
  
// macro definition 
#define LIMIT 5 

int main() 
{ 
    for (int i = 0; i < LIMIT; i++) { 
        std::cout << i << "
"; 
    } 
  
    return 0; 
} 
Comment

function c++

#include <iostream>
using namespace std;

// declaring a function
void displayNum(int n1, float n2) {
    cout << "The int number is " << n1;
    cout << "The double number is " << n2;
}

int main() {
     int num1 = 5;
     double num2 = 5.5;
  
    // calling the function
    displayNum(num1, num2);
    return 0;
}
Comment

c++ function.

// C++ Program to demonstrate working of a function
#include <iostream>
using namespace std;
 
// Following function that takes two parameters 'x' and 'y'
// as input and returns max of two input numbers
int max(int x, int y)
{
    if (x > y)
        return x;
    else
        return y;
}
 
// main function that doesn't receive any parameter and
// returns integer
int main()
{
    int a = 10, b = 20;
 
    // Calling above function to find max of 'a' and 'b'
    int m = max(a, b);
 
    cout << "m is " << m;
    return 0;
}
Comment

what is c++ function

return_type function_name( parameter list ) {
   body of the function
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp define 
Cpp :: SUMOFPROD2 codechef solution 
Cpp :: size() in c++ SET 
Cpp :: how to remove maximum number of characters in c++ cin,ignore 
Cpp :: stl c++ 
Cpp :: for loop in cpp 
Cpp :: how to use command line arguments with integers in c++ 
Cpp :: c++ random number 
Cpp :: Youtube backlink generator tool 
Cpp :: C++ Nested if...else 
Cpp :: length of a string c++ 
Cpp :: cpp linked list 
Cpp :: lower bound and upper bound in c++ 
Cpp :: how to grab numbers from string in cpp 
Cpp :: CRED Coins codechef solution in c++ 
Cpp :: convert wchar_t to to multibyte 
Cpp :: c++ program to print odd numbers using loop 
Cpp :: c++ class 
Cpp :: if argv == string 
Cpp :: C++ Arrays and Loops 
Cpp :: c++ pop string from vector 
Cpp :: c++ list of pairs 
Cpp :: files in c++ 
Cpp :: how to run cpp using gcc vscode 
Cpp :: how to convert char to int in c++ 
Cpp :: c++ define function pointer 
Cpp :: public method 
Cpp :: initialisation of a c++ variable 
Cpp :: is there garbage collection in c++ 
Cpp :: c++ method name 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =