Design Develop and Implement of Program in C for Creating and Display of Array Elements.

Welcome to everyone in this post we are showing the some array operation, for 3rd Sem Data structure and application lab 1st question

Design, Develop and Implement a menu driven Program in C for the following Array Operations
a. Creating an Array of N Integer Elements
b. Display of Array Elements with Suitable Headings
c. Exit.

/*Design, Develop and Implement a menu driven Program in C for the following Array Operations
a. Creating an Array of N Integer Elements
b. Display of Array Elements with Suitable Headings
c. Exit.*/

#include <stdio.h>
#include <stdlib.h>

#define MAX_ELEMENTS 100

void createArray(int array[], int n);
void displayArray(int array[], int n);

int main()
{
    int array[MAX_ELEMENTS];
    int choice, n;

    while (1)
    {
        printf("\nArray Operations:\n");
        printf("1. Create an Array of N Integer Elements\n");
        printf("2. Display Array Elements\n");
        printf("3. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch(choice)
        {
            case 1:
                printf("Enter the number of elements: ");
                scanf("%d", &n);
                createArray(array, n);
                break;
            case 2:
                displayArray(array, n);
                break;
            case 3:
                exit(0);
            default:
                printf("Invalid choice\n");
        }
    }
    return 0;
}

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

void displayArray(int array[], int n)
{
    int i;
    printf("Array elements:\n");
    for (i = 0; i < n; i++)
    {
        printf("%d\n", array[i]);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *