C program to Find the Sum and Average of Three Numbers

Write a C program to find the sum and average of three numbers. This C example accepts three integer values and calculates the sum and average of those values.

#include <stdio.h>

int main()
{   
    int num1, num2, num3, sum;
    float avg;
    
    printf("Enter the First Number  = ");
    scanf("%d",&num1);

    printf("Enter the Second Number = ");
    scanf("%d",&num2);

    printf("Enter the Third Number  = ");
    scanf("%d",&num3);
    
    sum  = num1 + num2 + num3;

    avg = sum / 3;

    printf("\nThe Sum of Three Numbers     = %d", sum); 
    printf("\nThe Average of Three Numbers = %.2f\n", avg);
}
C program to Find the Sum and Average of Three Numbers

This c program finds the sum and average of three floating point numbers.

#include <stdio.h>

int main()
{   
    float num1, num2, num3, sm, ag;
    
    printf("Enter the First Float  = ");
    scanf("%f",&num1);

    printf("Enter the Second Float = ");
    scanf("%f",&num2);

    printf("Enter the Third Float  = ");
    scanf("%f",&num3);
    
    sm  = num1 + num2 + num3;

    ag = sm / 3;

    printf("\nThe Sum      = %.2f", sm); 
    printf("\nThe Average  = %.2f\n", ag);
}
Enter the First Float  = 22.5
Enter the Second Float = 55.9
Enter the Third Float  = 128.7

The Sum     = 207.10
The Average  = 69.03