-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_stuff.c
More file actions
56 lines (39 loc) · 823 Bytes
/
calc_stuff.c
File metadata and controls
56 lines (39 loc) · 823 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
51
52
53
54
55
56
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int fib(int);
int isqrt(int);
int main()
{
char line[82];
int n;
printf("Enter integer: ");
fgets(line, sizeof line, stdin);
n = atoi(line);
printf("n: %i\n", n);
printf("fib(%i) := %i\n", n, fib(n));
printf("interger sqrt(%i):= %i\n", n, isqrt(n));
printf("floating point sqrt(%i)= %f\n",n,sqrt((float)n));
}
int isqrt(int n)
{
int result = 1;
for( int i = 1; i*i <= n; ++i )
result = i;
return result;
}
int fib(int n){
int first = 0, second = 1, next, c;
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
}
return next;
}