How to find Average of Two Numbers in C - Step by Step Examples



How to find Average of Two Numbers in C ?

Answer

To find the average of two numbers in C, you can add the two numbers and then divide the sum by 2.

How to find Average of Two Numbers in c language

✐ Examples

1 Average of Two Numbers

In this example,

  1. We declare two variables a and b to store the numbers for which we want to find the average.
  2. We initialize these variables with the desired values.
  3. We add the two numbers a and b and store the sum in a variable sum.
  4. We then divide the sum by 2 to calculate the average and store it in a variable average.
  5. Finally, we print the value of average to display the average of the two numbers.

C Program

#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;
}

Output

Average of 5 and 10 is 7.50

Summary

In this tutorial, we learned How to find Average of Two Numbers in C language with well detailed examples.




More C Arithmetic Operations Tutorials

  1. How to Add Two Numbers in C ?
  2. How to find the Subtraction of Two Numbers in C ?
  3. How to Multiply Two Numbers in C ?
  4. How to find the Division of Two Numbers in C ?
  5. How to find Average of Two Numbers in C ?
  6. How to find Average of Three Numbers in C ?