🔒 Closed Create a c program that will initialize an array is by using the index of each element

Status
Not open for further replies.
C:
/**
 * C program to read and print elements in an array
 */

#include <stdio.h>
#define MAX_SIZE 1000 // Maximum array size

int main()
{
    int arr[MAX_SIZE]; // Declare an array of MAX_SIZE
    int i, N;

    /* Input array size */
    printf("Enter size of array: ");
    scanf("%d", &N);

    /* Input elements in array */
    printf("Enter %d elements in the array : ", N);
    for(i=0; i<N; i++)
    {
        scanf("%d", &arr[i]);
    }


    /*
     * Print all elements of array
     */
    printf("\nElements in array are: ");
    for(i=0; i<N; i++)
    {
        printf("%d, ", arr[i]);
    }

    return 0;
}
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 315
    Views
  • 2
    Participants
Last reply from:
geneodan

Online now

Members online
1,062
Guests online
714
Total visitors
1,776

Forum statistics

Threads
2,276,976
Posts
28,973,524
Members
1,229,678
Latest member
wow98
Back
Top