This program searches for and deletes an entered value, it has two steps:
Browse the list until the search is complete and save the index in a variable k.
delete the value at index k.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include<stdio.h> #include<stdlib.h> int i,k; struct { int l; int t[50]; }tab; void sup(int t[20],int k) { for(i=k;i<tab.l;i++) t[i]=t[i+1]; tab.l--; } main() { //Change the color of the interface to blue system("color 9e"); int val; printf("give the dimension of the painting "); do scanf("%d",&tab.l); //the size of the table must not exceed 50 while((tab.l>=50)||(tab.l<=0)); //fill in the table with the values for(i=0;i<tab.l;i++) { printf("T[%d]=",i); scanf("%d",&tab.t[i]); } //table display printf("Table display \n"); for(i=0;i<tab.l;i++) printf("\t\tT[%d]=%d\n",i,tab.t[i]); printf("Give the value of the item to delete "); scanf("%d",&val); //Find the value in the table and delete the for(k=0;k<tab.l;k++) if(tab.t[k]==val) sup(tab.t,k); puts(""); //Display after deletion printf("Display New table \n"); for(i=0;i<tab.l;i++) printf("\t\tT[%d]=%d\n",i,tab.t[i]); system("pause"); return 0; } |