Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE 100
- typedef unsigned long ulong;
- ulong max(ulong *seq, int len){
- ulong top = 0;
- while(--len){
- if(top < *(seq+len)) top = *(seq+len);
- }
- return top;
- }
- void calc_seq(ulong *seq, int len){
- int i = *(seq+1) = *seq = 1;
- while( (i<<1)+1 < len) {
- *(seq+(i<<1)) = *(seq+i)+*(seq+i-1);
- *(seq+(((i++)<<1)+1)) = *(seq+i);
- }
- if((len%2) != 0){
- *(seq+(i<<1)) = *(seq+i)+*(seq+i-1);
- }
- }
- ulong calc_max_in_sec(ulong *seq, int len){
- calc_seq(seq, len);
- return max(seq,len);
- }
- int main()
- {
- // stack allocation
- ulong tab[SIZE];
- printf("stack: %li\n", calc_max_in_sec(tab, SIZE));
- // heap allocation
- ulong *tab_heap = malloc(sizeof(ulong) * SIZE);
- printf("heap: %li\n", calc_max_in_sec(tab, SIZE));
- free(tab_heap);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement