C program to find average of two and three numbers

 C Program To Find Average Of Two Numbers

A simple c program to find average of two numbers, first we will take input from user and store in n1, n2 variables and then compute average and display it on the screen.

C program to find average of two and three numbers
C program to find average of two and three numbers



Algorithm:-

  1. Start
  2. Read n1 and n2
  3. Compute Average
  4. Print result
  5. Stop.

Program:-


#include <stdio.h>

int main()
{
    int n1, n2, avg=0;
    printf("Enter two numbers: ");
    scanf("%d %d", &n1, &n2);
    
    avg=(n1+n2)/2;
    
    printf("The average of two numbers is: %d", avg);

    return 0;
}

Output:-

Enter two numbers: 10 20
The average of two numbers is: 15


 C Program To Find Average Of Two Numbers

#include <stdio.h>

int main()
{
    int n1, n2, n3, avg=0;
    printf("Enter three numbers: ");
    scanf("%d %d %d", &n1, &n2, &n3);
    
    avg=(n1+n2+n3)/3;
    
    printf("The average of two numbers is: %d", avg);

    return 0;
}

Output:-

Enter three numbers: 10 20 30 The average of two numbers is: 20

Post a Comment

0 Comments