Posted in: E Learn

Programming C – Tutorial Code

#include <stdio.h>

int main() {
    int num1, num2, num3;
    int sum, max, min;
    float average;

    // Input numbers
    printf("Enter three numbers: ");
    scanf("%d %d %d", &num1, &num2, &num3);

    // Calculating sum
    sum = num1 + num2 + num3;

    // Calculating average
    average = sum / 3.0;

    // Finding maximum number
    max = num1;
    if (num2 > max) max = num2;
    if (num3 > max) max = num3;

    // Finding minimum number
    min = num1;
    if (num2 < min) min = num2;
    if (num3 < min) min = num3;

    // Printing results
    printf("Sum = %d\n", sum);
    printf("Average = %.2f\n", average);
    printf("Maximum = %d\n", max);
    printf("Minimum = %d\n", min);

    return 0;
}

This program will prompt the user to enter three integers. It then calculates the sum, average, maximum, and minimum of these numbers and prints the results. The average is calculated as a floating-point number to allow for decimal places, and it’s formatted to two decimal places in the output.

See also  How to Draw a Mechanical Wrench in AutoCAD

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top