Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CremovePointFun
//gcc 7.4.0 //write a function that removes an item from an integer array(use pointer to function) //this code is created by Rezaul Hoque on June 07, 2021; contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <stdio.h> #include <stdlib.h> int n=5; int retPos(int [], int); void del(int [], int (*f)(int [],int )); /***retPos function takes two parameters: one is the array, the other one is the item to be removed; array elements are searched till the desired item is found; once the item is found, the function returns the index of the item in the array.****/ int retPos(int a[],int q){ printf("\nItem to be deleted:\n"); scanf("%d\t",&q);//read the item to be removed from the user for (int i=0; i<n;i++) if(a[i]==q)//if found return the index return i; } /***del function takes two parameters: one is the integer array and the other is a pointer to function; ***/ void del(int a[], int (*f)(int a[],int q)) { int b,x,q; x=(*f)(a,q);//x is assigned the value fed by pointer to function for (b=x;b<n;b++)//loop control variable b is initialized with the returned index(x) of the searched item;as long as it is less than the size of array, increment b and... a[b]=a[b+1];//value stored at index b of the resultant array is that of index b+1 of the initial array; remember one item is going to be removed so this reordering of the index is needed ... --n;//decrement n; } int main() { int a[5]={10,20,25,30,40};//the array //print the initial array printf("\nInitial array:\n"); for(int i=0;i<n;i++) printf("%d\t",a[i]); //the delete function is called to remove the item;note function retPos is in the parameter of the delete function del(a,retPos); //after removal of the item, print the new array printf("\nNew array:\n"); for(int i=0;i<n;i++) printf("%d\t",a[i]); return 0; }
run
|
edit
|
history
|
help
0
linear hybrid cellular automaton reversible random bit generator stream cipher
Project 3 Part 1 v1.4
main.c
Lab 7 blackjack v1.0
Assignment 3
Square pyramid
json formatter
print name
FILE_Access
c program for hollow rhombus