Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Input and Output :
- Enter the number of element in array 2
- 1 2
- I for instertion and D for deletion
- or any key to just print the array
- i
- Possition where you want to insert
- 2
- Now enter the element
- 0
- 1 0 2
- */
- #include<stdio.h>
- #include<conio.h>
- void Print(int [],int);
- void Insertion(int [],int);
- void Deletion(int [],int);
- int main(){
- int arr[20],n;
- printf("Enter the number of element in array ");
- scanf("%d",&n);
- for(int i=0 ; i<n ; i++){
- scanf("%d",&arr[i]);
- }
- fflush(stdin);
- printf("I for instertion and D for deletion \nor any key to just print the array\n");
- char c; scanf("%c",&c);
- if(c=='I'|| c=='i'){
- Insertion(arr,n+1);
- }
- else if(c=='D' || c=='d'){
- Deletion(arr,n);
- }
- else
- Print(arr,n);
- return 0;
- }
- void Insertion(int arr[],int n){
- int pos,element;
- printf("\n\nPossition where you want to insert\n");
- scanf("%d",&pos);
- printf("Now enter the element\n");
- scanf("%d",&element);
- for(int i=n-2 ; i>=pos-1 ; i--){
- arr[i+1] = arr[i];
- }
- arr[pos-1]=element;
- Print(arr,n);
- }
- void Deletion(int arr[],int n){
- int pos;
- printf("Enter possition want to delete\n");
- scanf("%d",&pos);
- for(int i=pos-1 ; i<n-1 ; i++){
- arr[i]=arr[i+1];
- }
- Print(arr,n-1);
- }
- void Print(int arr[],int n){
- for(int i=0 ; i<n; i++){
- printf("%d ",arr[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment