46 lines
964 B
Plaintext
46 lines
964 B
Plaintext
|
|
int getValue() {
|
||
|
|
return 42;
|
||
|
|
}
|
||
|
|
|
||
|
|
int add(int a, int b) {
|
||
|
|
return a + b;
|
||
|
|
}
|
||
|
|
|
||
|
|
int square(int x) {
|
||
|
|
int result = x * x;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
int max(int a, int b) {
|
||
|
|
if (a > b) {
|
||
|
|
return a;
|
||
|
|
}
|
||
|
|
return b;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
printf("=== Functions Tests ===\n");
|
||
|
|
printf("Testing no-parameter functions...\n");
|
||
|
|
int val = getValue();
|
||
|
|
printf("getValue() = %d\n", val);
|
||
|
|
|
||
|
|
printf("Testing two-parameter functions...\n");
|
||
|
|
int sum = add(5, 3);
|
||
|
|
printf("add(5, 3) = %d\n", sum);
|
||
|
|
|
||
|
|
printf("Testing functions with local variables...\n");
|
||
|
|
int sq = square(7);
|
||
|
|
printf("square(7) = %d\n", sq);
|
||
|
|
|
||
|
|
printf("Testing conditional functions...\n");
|
||
|
|
int m1 = max(15, 20);
|
||
|
|
printf("max(15, 20) = %d\n", m1);
|
||
|
|
|
||
|
|
printf("Testing nested function calls...\n");
|
||
|
|
int nested = add(square(3), getValue());
|
||
|
|
printf("add(square(3), getValue()) = %d\n", nested);
|
||
|
|
|
||
|
|
printf("\n=== All Tests Completed ===\n");
|
||
|
|
return 0;
|
||
|
|
}
|