Skip to content

Instantly share code, notes, and snippets.

@abidrahmank
Created June 19, 2014 05:09
Show Gist options
  • Save abidrahmank/b4f6e4f0313c5034d1cc to your computer and use it in GitHub Desktop.
Save abidrahmank/b4f6e4f0313c5034d1cc to your computer and use it in GitHub Desktop.
#include <stdio.h>
int square(int x);
int cube(int x);
void map(int, int, int func(int));
int main(){
map(1,5,square);
map(1,5,cube);
}
int square(int x){
return x*x*x*x;
}
int cube(int x){
return x*x*x;
}
void map( int first, int last, int func(int res) ){
// apply a map function to integers from first to last
// eg: map(1,5,square) --> [1,4,9,16,25]
int i, temp;
for(i=first; i<=last; ++i){
temp = func(i);
printf("%d %d\n", i, temp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment