diff --git a/Intermediate/arrayOperations.c b/Intermediate/arrayOperations.c new file mode 100644 index 00000000..6ed223ae --- /dev/null +++ b/Intermediate/arrayOperations.c @@ -0,0 +1,119 @@ +#include +int main() +{ + + int a[100]; + int n; + printf("Enter the size of array:- "); + scanf("%d",&n); + printf("Enter the elements:- "); + for(int i = 0; i n+1 || pos <= 0) + { + printf("Invalid position! Please enter position between 1 to %d", n); + } + else + { + + /* Make room for new array element by shifting to right */ + for(int i = n ; i>=pos; i--) + { + a[i] = a[i-1]; + } + /* Insert new element at given position and increment size */ + a[pos-1] = val; + n+=1; + printf("New Array\n"); + for(int i = 0; i n) + { + printf("Invalid position! Please enter position between 1 to %d", n); + } + else + { + + /* Copy next element value to current element */ + for(int i = position-1 ; ia[j+1]) + { + temp = a[j]; + a[j] = a[j+1]; //swapping of elements + a[j+1] = temp; + } + } + } + printf("New array\n"); + for(int i = 0;i