Skip to content

Commit d4f0dc5

Browse files
hoklaamct2013anurag
authored andcommitted
Fib in c (#1115)
* Change insertion sort in python * Add fibonacci in C
1 parent 6988fde commit d4f0dc5

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

nth_fibonacci/NthFibonacci.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int i, n, t1 = 0, t2 = 1, nextTerm;
5+
printf("Enter the number of terms: ");
6+
scanf("%s", &n);
7+
8+
printf("Fibonacci series: ");
9+
10+
for (i = 1; i <= n; ++i) {
11+
printf("%d", t1);
12+
nextTerm = t1 + t2;
13+
t1 = t2;
14+
t2 = nextTerm;
15+
}
16+
return 0;
17+
}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
arr = [12, 11, 13, 5, 6, 45, 99, 1, 654] # Array to sort
22

3-
for i in range(1, len(arr)):
4-
j = i - 1
5-
key = arr[i]
6-
7-
while j >= 0 and key < arr[j]:
8-
arr[j+1] = arr[j]
9-
j -= 1
10-
11-
arr[j+1] = key
12-
13-
i += 1
3+
for i in range(len(arr)):
4+
key = i
5+
for j in range(i+1, len(items)):
6+
if arr[key] > arr[j]:
7+
key = j
8+
arr[i], arr[key] = arr[key], arr[i]
149

1510
# print the sorted array
1611
print arr

0 commit comments

Comments
 (0)