-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample3.c
More file actions
52 lines (41 loc) · 825 Bytes
/
example3.c
File metadata and controls
52 lines (41 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#define MAX 100
// init array with Fionacci numbers and finds a specific number and returns the index
void printArray(uint64_t *);
void initArray(uint64_t *);
int findNum(uint64_t *, uint16_t);
int main()
{
uint64_t array[MAX];
//int index, selectedNum;
initArray(array);
printArray(array);
return 0;
}
void printArray(uint64_t *array)
{
uint16_t i;
for(i=0; i < MAX; ++i)
printf("[%"PRIu16"] %"PRIu64"\n",i,array[i]);
}
void initArray(uint64_t *array)
{
int i;
array[0] = 0;
array[1] = 1;
for(i=2; i < MAX; ++i){
array[i] = array[i-1] + array[i-2];
}
}
int findNum(uint64_t *array, uint16_t num)
{
uint16_t i;
for(i=0; i < MAX; ++i){
if (array[i]==num)
return i;
}
return -1;
}