Home / Questions / How to read and write data in an array?
Explanatory Question

How to read and write data in an array?

👁 904 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

In this section you will learn how to read and write data in an array using c programming Language


#include <stdio.h>

int main()
{
    int array[10], n, i;

    // Reading array size
    printf("Enter size of the array (max 10): ");
    scanf("%d", &n);

    // Reading array elements
    printf("Enter array elements:\n");
    for (i = 0; i < n; i++) {
        scanf("%d", &array[i]);
    }

    // Writing (printing) array elements
    printf("Array elements are:\n");
    for (i = 0; i < n; i++) {
        printf("%d ", array[i]);
    }

    return 0;
}