You're online now.

Hurray! you are online now.

Write a C program to Insert element in array

// Write a C Program to insert an element in array.
    #include<stdio.h>
    int main(){
    	int arr[100], size, location, element;
    	printf("Enter the size of the array : ");
    	scanf("%d", &size);
    	printf("Enter the element in array : ");
    	for(int i = 0; i < size; i++){
    		scanf("%d", &arr[i]);
    	}
    	printf("Enter the location where you want to insert element : ");
    	scanf("%d", &location);
    	printf("Enter the element which you want to insert : ");
    	scanf("%d", &element);
    	for(int i = size - 1; i >= location - 1; i--){
    		arr[i + 1] = arr[i];
    	}
    	arr[location-1] = element;
    	// resultant array
    	printf("After insert the array : ");
    	for(int i = 0; i <= size; i++){
    		printf("%d ", arr[i]);
    	}
    	return 0;
    }
🖤 0
Buy me coffee ☕

Comments

Oops!

No comments here...