Question 01

Write a C program that defines a function called max_of_three which takes three integers as parameters and returns the largest of the three integers. The program should prompt the user to enter three integers, call the max_of_three function, and display the result.

Question 02

Write a C program that defines a function called gcd which calculates the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. The program should prompt the user to enter two integers, call the gcd function, and display the result.

Question 03

Write a C program that defines a function called sum_of_digits which calculates the sum of the digits of a given positive integer. The program should prompt the user to enter a number, call the sum_of_digits function, and display the sum of its digits.

Question 04

Write a C program that defines two functions:

  1. A function is_even which takes an integer and returns 1 if the number is even and 0 if the number is odd.

  2. A function print_even_or_odd that calls is_even and prints Even if the number is even or Odd if the number is odd.

The program should prompt the user to enter an integer, call print_even_or_odd, and display whether the number is even or odd.

Question 05

Write a C program that defines three functions:

  1. A function is_positive which checks if an integer is positive (returns 1 if positive, 0 otherwise).

  2. A function is_negative which checks if an integer is negative (returns 1 if negative, 0 otherwise).

  3. A function check_number that calls both is_positive and is_negative to determine if the number is positive, negative, or zero, and prints the appropriate message.

The program should prompt the user to enter an integer, call the check_number function, and display whether the number is positive, negative, or zero.

Last modified: Wednesday, 11 December 2024, 8:36 AM