Complete the code to return the sum of two integers.
int add(int a, int b) {
return [1];
}The function should return the sum of a and b, so a + b is correct.
Complete the code to return the maximum of two integers.
int max(int x, int y) { if (x > y) { return [1]; } else { return y; } }
If x is greater than y, the function should return x.
Fix the error in the function to correctly return the length of a string.
#include <string.h> int string_length(char *str) { int len = strlen(str); return [1]; }
The function calculates the length and stores it in len, so it should return len.
Fill both blanks to return the product of two numbers and print it.
#include <stdio.h> int multiply(int a, int b) { return [1]; } int main() { int result = multiply(3, 4); printf("Product: %d\n", [2]); return 0; }
The function should return the product a * b, and the printf should print the variable result which holds the product.
Fill all three blanks to create a function that returns the absolute value of an integer and use it in main.
#include <stdio.h> int absolute([1] num) { if (num [2] 0) { return -num; } else { return num; } } int main() { int val = -10; int abs_val = absolute([3]); printf("Absolute value: %d\n", abs_val); return 0; }
The function parameter should be an int. The condition checks if num < 0. In main, we pass val to the function.