FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
1 like 0 dislike
50.0k views
in VTU B.Tech (CSE-III Sem) Data Structure Lab by Goeduhub's Expert (7.6k points)
retagged by

Design, Develop and Implement a menu driven Program in C for the following array

operations.

  • Creating an array of N Integer Elements
  • Display of array Elements with Suitable Headings
  • Inserting an Element (ELEM) at a given valid Position (POS)
  • Deleting an Element at a given valid Position (POS)
  • Exit.

Support the program with functions for each of the above operations.

1 Answer

1 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Design, Develop and Implement a menu driven Program in C for the following array operations

Array : An array is defined as finite ordered collection of homogenous data, stored in contiguous memory locations.

  • finite means data range must be defined.
  • ordered means data must be stored in continuous memory addresses.
  • homogenous means data must be of similar data type.

To know  about Arrays Click Here

Program 

#include<stdio.h>

#include<stdlib.h>

int a[10], pos, elem;

int n = 0;

void create();

void display();

void insert();

void del();

void main()

{

            int choice;

            while(1)

            {

             printf("\n\n~~~~MENU~~~~");

            printf("\n=>1. Create an array of N integers");

            printf("\n=>2. Display of array elements");

            printf("\n=>3. Insert ELEM at a given POS");

           printf("\n=>4. Delete an element at a given POS");

           printf("\n=>5. Exit");

           printf("\nEnter your choice: ");

           scanf("%d", &choice);

           switch(choice)

           {

             case 1: create();

                  break;

            case 2: display();

                  break;

           case 3: insert();

                  break;

           case 4:del();

                  break;

           case 5:exit(1);

                  break;

        default:printf("\nPlease enter a valid choice:");

                        }

            }

}

void create()

{

            int i;

            printf("\nEnter the number of elements: ");

            scanf("%d", &n);

            printf("\nEnter the elements: ");

            for(i=0; i<n; i++)

            {

                        scanf("%d", &a[i]);

            }

}

void display()

{

            int i;

            if(n == 0)

            {

                        printf("\nNo elements to display");

                        return;

            }

            printf("\nArray elements are: ");

            for(i=0; i<n;i++)

                        printf("%d\t ", a[i]);

}

void insert()

{

            int i;

            if(n == 5)

            {

        printf("\nArray is full. Insertion is not possible");

                        return;

            }

            do

            {

printf("\nEnter a valid position where element to be inserted:    ");

scanf("%d", &pos);

            }while(pos > n);

            printf("\nEnter the value to be inserted:   ");

            scanf("%d", &elem);

            for(i=n-1; i>=pos ; i--)

            {

                        a[i+1] = a[i];

            }

            a[pos] = elem;

            n = n+1;

            display();

}

void del()

{

            int i;

           

            if(n == 0)

            {

                        printf("\nArray is empty and no elements to delete");

                        return;

            }

            do

            {

                        printf("\nEnter a valid position from where element to be deleted:    ");

                        scanf("%d", &pos);

            }while(pos>=n);

            elem = a[pos];

            printf("\nDeleted element is : %d \n", elem);

            for( i = pos; i< n-1; i++)

            {

                        a[i] = a[i+1];

            }

            n = n-1;

            display();

Output

output


For more Visvesvaraya Technological University(VTU) CSE-III Sem Data Structure Lab Experiments Click Here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...