Removing elements from an array in C

后端 未结 6 852
你的背包
你的背包 2020-12-02 23:37

I just have a simple question about arrays in C

What\'s the best way to remove elements from an array and in the process make the array smaller.

i.e the ar

6条回答
  •  自闭症患者
    2020-12-02 23:52

    Try this simple code:

    #include 
    #include 
    void main(void)
    { 
        clrscr();
        int a[4], i, b;
        printf("enter nos ");
        for (i = 1; i <= 5; i++) {
            scanf("%d", &a[i]);
        }
        for(i = 1; i <= 5; i++) {
            printf("\n%d", a[i]);
        }
        printf("\nenter element you want to delete ");
        scanf("%d", &b);
        for (i = 1; i <= 5; i++) {
            if(i == b) {
                a[i] = i++;
            }
            printf("\n%d", a[i]);
        }
        getch();
    }
    

提交回复
热议问题