#include <iostream>
// Function prototype for a function that takes two integers and returns their sum
int add(int x, int y);
// Function prototype for a function that takes no arguments and returns nothing
void print_hello();
// Function prototype for a function that takes an array of integers and its size, and returns the sum of all elements
int sum_array(int *arr, int size);
int main() {
// Call the add function
int x = 3, y = 4;
int result = add(x, y);
std::cout << "The sum of " << x << " and " << y << " is " << result << std::endl;
// Call the print_hello function
print_hello();
// Call the sum_array function
int arr[] = {1, 2, 3, 4};
int array_sum = sum_array(arr, 4);
std::cout << "The sum of all elements in the array is " << array_sum << std::endl;
return 0;
}
// Definition of the add function
int add(int x, int y) {
return x + y;
}
// Definition of the print_hello function
void print_hello() {
std::cout << "Hello, World!" << std::endl;
}
// Definition of the sum_array function
int sum_array(int *arr, int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
return sum;
}
0 Comments