C program to insert an element into an array.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>//Insert Element into Array
int main()
{
        int s = 6;
        int arr[s] = {5, 10, 15, 20, 25, 30}, pos = 2, value = 96, i;

        for(i = s - 1; i >= pos; i--){
                arr[i + 1] = arr[i];
        }
        
        arr[pos] = value;
        for(i = 0; i < s + 1; i++){
                printf("%d\t", arr[i]);
        }
        printf("\n\n");
        return 0;
}


No comments:

Post a Comment