✏️ Explanatory Question

How to read and write data in an array?

👁 904 Views
📘 Detailed Answer
904
Total Views
10
Related Qs
0%
Progress
💡

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;
}