+ 1

Write a program for insertion in array, deletion, searching and traversal using c

27th Dec 2022, 5:58 PM
Ritu Hada
8 Réponses
+ 1
I tried to do this much but after including this i have to do searching and traversing also in my program
27th Dec 2022, 6:16 PM
Ritu Hada
0
No
27th Dec 2022, 6:04 PM
Ritu Hada
0
Help me in solving this problem
27th Dec 2022, 6:05 PM
Ritu Hada
0
#include <stdio.h> #include <stdlib.h> int main() { int a[100]; int element,i,loc,size,n,j,choice; printf("Program Insert,search,delete and traverse.\n"); printf("\n1. Insert_Element 2. Delete_Element\n"); printf("Enter choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the size of an array\n"); scanf("%d",&size); printf("Enter %d array elements\n",size); for(i=0;i<size;i++) { scanf("%d",&a[i]); } printf("List before Insertion: "); for(i=0;i<size;i++) { printf("%d ",a[i]); } printf("\ninsert element\n"); scanf("%d",&element); printf("position to insert element %d\n",element); scanf("%d",&loc); loc--; for(i=size-1;i>=loc;i--) { a[i+1]=a[i]; } a[loc]=element; printf("after Insertion: "); for(i=0;i<size+1;i++) { printf("%d ",a[i]);
27th Dec 2022, 6:16 PM
Ritu Hada
0
Thanx
27th Dec 2022, 6:40 PM
Ritu Hada
0
#include <stdio.h> void insertion() { int LA[] = {1,3,5,7,8}; int item = 10, k = 3, n = 5; int i = 0, j = n; n++; while( j >= k) { LA[j+1] = LA[j]; j = j - 1; } LA[k] = item; printf("\nThe array elements after insertion :\n"); for(i = 0; i<n; i++) { printf("LA[%d] = %d ", i, LA[i]); } printf("\n"); } void deletion(){ int LA[] = {1,3,5,7,8}; int i,j,k=3,n=5; j = k; while( j < n) { LA[j-1] = LA[j]; j = j + 1; } n = n -1; printf("\nAfter Deletion :\n"); for(i = 0; i<n; i++) { printf("LA[%d] = %d ", i, LA[i]); } printf("\n"); } void search() { int LA[] = {1,3,5,7,8}; int item = 5, n = 5; int i = 0, j = 0; while( j < n){ if( LA[j] == item ) { break; } j = j + 1; } printf("\nSearching: \nFound element %d at position %d\n", item, j+1); } void traverse(){ int LA[] = {1,3,5,7,8}; int i, n=5; printf("\nTraversing elements in array:\n");
27th Dec 2022, 6:40 PM
Ritu Hada
0
Paste your code in code bit your shared code is incomplete copy code link and paste here .don't write such a big statements in switch case just make a function separately and call them in cases . give a meaningful name to identifiers so it will be easy to read your code
27th Dec 2022, 7:17 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Ok
27th Dec 2022, 7:18 PM
Ritu Hada