------------------------------------------------------------------------------
MC logo
Average C I/O
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Hello, World! (Plain C)] [Average C I/O] [Printf Demo] [Problems With C I/O] [Looping On Read] [Convert To Upper Case] [Indent and Blank Remover] [Reading Lines] [Safer Line Reading] [Printing C++ Strings]
average1.c
#include <stdio.h>
int main(void)
{
        // Read the numbers.
        int n1, n2, n3;
        printf("Enter Three Integers: ");
        scanf("%d %d %d", &n1, &n2, &n3);

        // Compute the sum and average.
        double sum = n1 + n2 + n3;
        printf("Mean %d %d %d is %f\n", n1, n2, n3, sum/3.0);

        return 0;
}

The primary calls for formatted I/O are scanf and printf. The first parameter for each is a string format which describes the layout. The % is followed by a letter indicating the type. The format items apply to the data follwing the format in the same order. For scanf, the user must send pointers so that the system can update the variables.