🔒 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
  • 319
    Views
  • 2
    Participants
Last reply from:
geneodan

Trending Topics

Online now

Members online
324
Guests online
1,402
Total visitors
1,726

Forum statistics

Threads
2,287,449
Posts
29,044,735
Members
1,216,542
Latest member
zutr3k17
Back
Top