Solved programming problem

Delete an element from a 1D array in C.

Source code

#include<stdio.h>

int main()

{

    int array[50],n,m,i;

    printf("Please enter the number of element you want to use in the array:");

    scanf("%d",&n);

    printf("
Please enter %d elements of the array:
",n);

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

    {

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

    }

    printf("Please enter which position you want to skip: ");

    scanf("%d",&m);

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

    {

        if(i>=m)

        {

            array[i]=array[i+1]; ///saving all i+1 index element to i index

        }

    }

    n--;/// reduce the array size.

   

    printf("
Your array is: ");

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

    {

        printf("%d ",array[i]);

    }

    printf("
");

    return 0;

}

Output

Please enter the number of element you want to use in the array:5

Please enter 5 elements of the array:

23 43 12 43 6

Please enter which position you want to skip:3

Your array is: 23 43 12 6

Join the discussion

Add your comment

1 previous comment

JefAddete

Emqpvx [url=https://newfasttadalafil.com/]buying cialis online safe[/url] Dtyhvg generic cialis overnight <a href=https://newfasttadalafil.com/>buy generic cialis online safely</a> Aludon Ekviez https://newfasttadalafil.com/ - cialis generic Jbboub