Home

A program to declare a single dimensional array

C Programming Language 050

The following code shows how to write a program to declare a single dimensional array. Read values into the array and print them.

Program

#include <stdio.h>

void main() {
    int a[4], i;
    printf("Enter the values:\n");

    for ( i = 0; i < 4; i++)
    {
        scanf("%d", &a[i]);
    }

    printf("The values are:\n");
    for ( i = 0; i < 4; i++)
    {
        printf("%d\n", a[i]);
    }
    

    printf("\n");
}

Result

Enter the values:
1 5 3 4
The values are:
1
5
3
4


Last Updated on

Next Post: Rules vs Guidelines →

Comments