C Program to Read and Print a 1D Array

Subject: PPS (Programming for Problem Solving)

Contributed By: Sanjay

Created At: February 3, 2025

Question:


Write a C Program to Read and Print a 1D Array

Explanation Video:

Custom Image

Explanation:

 

A one-dimensional array is read using a loop, and the values are displayed.

Source Code:
#include <stdio.h>

int main() {
    int arr[5], i;
    printf("Enter 5 elements: ");
    for (i = 0; i < 5; i++)
        scanf("%d", &arr[i]);

    printf("Array elements are: ");
    for (i = 0; i < 5; i++)
        printf("%d ", arr[i]);

    return 0;
}
Input:
Enter 5 elements: 1 2 3 4 5
Output:
Array elements are: 1 2 3 4 5
Share this Article & Support Us:
Status
printf('Loading...');