To find the average of two numbers in C, you can add the two numbers and then divide the sum by 2.
In this example,
a
and b
to store the numbers for which we want to find the average.a
and b
and store the sum in a variable sum
.sum
by 2 to calculate the average and store it in a variable average
.average
to display the average of the two numbers.#include <stdio.h>
int main() {
int a = 5, b = 10;
int sum = a + b;
float average = sum / 2.0;
printf("Average of %d and %d is %.2f\n", a, b, average);
return 0;
}
Average of 5 and 10 is 7.50
In this tutorial, we learned How to find Average of Two Numbers in C language with well detailed examples.