function.cpp
Server-Architecture-Firmware/function.cpp
#include <iostream>
using namespace std;
// Function to calculate the square of a number
int square(int num) {
return num * num;
}
// Function to check if a number is even
bool isEven(int num) {
return num % 2 == 0;
}
// Function with default parameter
void greet(string name = "Guest") {
cout << "Hello, " << name << "!" << endl;
}
int main() {
int number = 7;
cout << "Square of " << number << " is: " << square(number) << endl;
if (isEven(number)) {
cout << number << " is even." << endl;
} else {
cout << number << " is odd." << endl;
}
greet(); // Uses default parameter
greet("Alice"); // Provides a name
return 0;
}
Articoli correlati
Armstrong.cpp
Armstrong.cpp — cpp source code from the Server-Architecture-Firmware learning materials (Server-Architecture-Firmware/Armstrong.cpp).
Leggi l'articolo →MaxOfTwo.cpp
MaxOfTwo.cpp — cpp source code from the Server-Architecture-Firmware learning materials (Server-Architecture-Firmware/MaxOfTwo.cpp).
Leggi l'articolo →RTTI.cpp
RTTI.cpp — cpp source code from the Server-Architecture-Firmware learning materials (Server-Architecture-Firmware/RTTI.cpp).
Leggi l'articolo →console_input.cpp
console_input.cpp — cpp source code from the Server-Architecture-Firmware learning materials (Server-Architecture-Firmware/console_input.cpp).
Leggi l'articolo →main.cpp
main.cpp — cpp source code from the Server-Architecture-Firmware learning materials (Server-Architecture-Firmware/main.cpp).
Leggi l'articolo →manyifelse.cpp
manyifelse.cpp — cpp source code from the Server-Architecture-Firmware learning materials (Server-Architecture-Firmware/manyifelse.cpp).
Leggi l'articolo →