In the previous post we saw two not equal numbers. Now, we will see about average of three numbers in C.

Basic Data Type:- int, char, float, double

int Datatype:- Its an integer datatype .Its of 2 bytes .Its range is −32,768 to 32,767.

char Datatype:-Its an character datatype. Its of  1 byte. Its range is -128 to 127 .

float Datatype:-Its for floating point numbers. Its of  4 byte.

double Datatype :-Its for large floating point numbers .Its of 8 byte.

Code:-

#include <stdio.h>

int main()

{

    int n1,n2,n3,avg;

    printf("Enter all the three numbers");

    scanf("%d %d %d",&n1,&n2,&n3);

    avg=(n1+n2+n3)/3;

    printf("The average of three numbers is %d ",avg);

    return 0;

}

Algorithm:-

1.Start 

2.To get the input of three numbers declare the variable as n1,n2,n3 which indicates number1,number2,number3 which is of int type by using scanf statement and using format specifier as "%d".

3.Use a variable called avg which is of int type  which indicates as average and now add the n1,n2,n3 variables and divide by a number 3.

Explanation:-We are dividing by number 3 because we have the three integer variables .

4.Finally print using the statement The average of three numbers is and print the avg variable.

5.Stop .

Screenshot:

1.Code Screenshot:-



2.Program Screenshot :-




In the next blog, we will see how to square a number in C.