Question

Write an interactive C program to insert new elements in the unsorted array

07 Aug 2023
Answer :
Word Count : 871

Here is the interactive C program to insert new elements in an unsorted array, along with an explanation of the approach taken in the program.

```c
#include <stdio.h>

#define MAX_SIZE 100 // Maximum size of the array

// Function to display the array
void displayArray(int arr[], int size) {
    printf("Current elements in the array: ");
    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
}

// Main function
int main() {
    int arr[MAX_SIZE]; // Array declaration
    int size; // Current size of the array
    int element; // Element to be inserted
    char choice; // User's choice for continuing

    // Input the size of the array
    printf("Enter the number of elements in the array (max %d): ", MAX_SIZE);
    scanf("%d", &size);

    // Check for valid size
    if (size < 0 || size > MAX_SIZE) {
        printf("Invalid size! Please restart the program and enter a size between 0 and %d.\n", MAX_SIZE);
        return 1;
    }

    // Input the elements of the array
    printf("Enter %d elements for the array:\n", size);
    for (int i = 0; i < size; i++) {
        printf("Element %d: ", i + 1);
        scanf("%d", &arr[i]);
    }

    // Display the initial array
    displayArray(arr, size);

    // Loop for inserting new elements
    do {
        // Check if there is space for more elements
        if (size == MAX_SIZE) {
            printf("Array is full! Cannot insert more elements.\n");
           

______ ____ ________ _______ ___ _________ ________ _______.
_________ ________ _______ ________ _________ ____ _________ __________.
___ _______ _________ _________ ________ _________ ______.
__________ __________ ______ _________ ___ ___ ____ ____ ________ ___ ____.
________ __________ ____ _______ _____ __________.
____ ______ ___ _________ ________ _________.
____ ____ ______ ________ _____ __________ _____ _______ _________ _______ ____ _______.
__________ _____ ____ ___ ______ ____ ________ __________.
_________ __________ __________ _________ __________ _____ ________ _________ ___ _____ _________ ___.
_______ _______ ___ ____ ____ ___ _______ ____ ________ ____ ___.
__________ ______ __________ __________ _____ _______ _______ ____ _______.
___ _________ __________ _________ ____ ______ __________.
______ ____ _____ _____ ___ ___ ___ ________.
__________ ____ ____ __________ __________ __________.
_______ _________ _________ ___ ____ _______ ___ ________ ___ ____ ________.
_________ ______ ______ __________ ______ _____ _______ _______ __________ _____ _______ ______.
__________ __________ ________ _______ _______.
__________ ____ __________ _____ ______ _______ ________ _________ ________ ________.
______ ____ ____ _____ ____ __________ __________ _____ ______ ___.
__________ ________ __________ ______ ______ ________ ____ _______ _____ ______ _____ _______.
___ ____ ________ ________ _____ _________ ________ _____.
____ __________ __________ ______ ____ ____ _________ ____ ___ ___ ________.
_________ _____ _____ ________ ________ _____.
_______ __________ _________ _____ ___ ______ __________.
_______ ______ ______ _________ _______ ___ _________ _____.
_______ ______ _________ ______ ________.
____ ___ ____ _____ ________ ____ _______ _______ _______ _______.
______ __________ ________ ________ ______.
_______ ________ __________ ______ ____ _________ ________.
________ _________ __________ ____ _________ __________ _________ ___ _____ _____.
______ ________ ______ _______ _________ _____.
________ _________ _______ ______ ______ ______ ______.
_________ ________ ___ _________ ____ ______ _________.
____ __________ ___ ____ _________ _____ _______ __________ ____ _________ ___.
____ _______ __________ ________ ___ ______ __________ _______.
_________ __________ ________ ________ _______ _____ _______.
_________ _____ _________ _______ ___ ___ ___ ________.
_____ _______ _____ __________ _________ _______ ________ ___ _______ _____ _________ _____.
_______ _____ _________ _____ _____ ________ ______ ______ _______.
___ _____ _______ ___ ______ ________ _____ ______ ____ ___ ____.
______ ____ ____ ________ ________.
__________ _________ ______ _________ _________.
______ _________ ________ __________ __________ __________ ________ ____ ________ ____ ____ ___.
_______ _______ _____ __________ __________ _____ ________ ________ _________.
________ ______ ________ ___ ____ ________ ___ __________ ________ _______.
_________ _________ __________ ________ _____.
_______ ____ ______ _________ _________ ________ ___ __________ ____ _________.
________ _____ ________ _______ __________ __________ ______ _____.
___ ________ ______ _________ ________ _________.
_______ _____ _____ __________ _____ _____ _________ ____ ________ _____ __________.
_________ _______ __________ __________ __________ ______ __________ __________ _________ ___.
_________ _______ _________ ________ ________ ______ ____ ________ _______ __________.
_________ __________ __________ __________ ____ _____.
___ __________ __________ ___ _______ __________ ___ ___.
_______ ___ ___ ____ ______ ________ ___ ____ __________ __________ ________ _______.
_____ ____ _____ _______ _____ _____ ___ ______ ____.
______ _____ ____ _________ ______.
______ _____ ____ _________ ___ _______ ____ ___ ____.
_____ _______ _______ ______ _______ __________ ____ _______.
_________ _____ __________ ______ ___.
__________ __________ ______ _____ _________ ______ ______ ____ ______ __________ ________ __________.
_______ _________ _____ ________ ______ __________ ________ ___ __________.
________ ______ __________ _______ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCS 11 2023 2024 - Write an interactive C program to insert new elements in the unsorted | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→