Created
March 23, 2011 04:27
-
-
Save radiofreejohn/882618 to your computer and use it in GitHub Desktop.
generate a range of integer values range(start,end) - may be neg to pos and vice versa
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> | |
#include <stdlib.h> | |
#include <math.h> | |
int *range(int, int); | |
int *range(int start, int end) | |
{ | |
int size = (int) fabs(end-start)+1; | |
int *values = malloc(size * sizeof(int)); | |
int i=0; | |
while (size--) | |
{ | |
*(values + (i++)) = start; | |
(start < end) ? start++ : start--; | |
} | |
return values; | |
} | |
int main() | |
{ | |
int *vals,i; | |
vals = range(200,150); | |
for (i=0;i<=50;i++) | |
printf("%d ", vals[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment