Created
June 19, 2014 05:09
-
-
Save abidrahmank/b4f6e4f0313c5034d1cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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