“CPP mendefinisikan fungsi” Kode Jawaban

fungsi C.

#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;
}
coder

CPP mendefinisikan fungsi

//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 "\n\n\t\tProgram has ended!!\n"   //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;
}
ALeonidou

Jawaban yang mirip dengan “CPP mendefinisikan fungsi”

Pertanyaan yang mirip dengan “CPP mendefinisikan fungsi”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya