-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecursion.c
130 lines (83 loc) · 2.23 KB
/
Recursion.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include<stdio.h>
void P_hello(int count);
int sum(int n);
int fact(int x);
float convertTem(float celsius);
int GeneratePercentage(int since, int math, int history); //..This is also another problem's solution functioni.
int fibo(int n);
int fibonacci(int x);///Actually this is a homework;
int main(){
fibonacci(7);
// printf("%d",fibo(6));
// int since = 40;
// int history = 50;
// int math = 67;
// int result_int_P = GeneratePercentage(since,math,history);
// printf("Your result is:%d ",result_int_P);
// printf(" Farhenite is: %f", convertTem(37));
// printf("sum is: %d",fact(5));
// P_hello(15);
return 0;
}
int fibonacci(int n){ //...........actually this was a problem.
int first=0;
int second=1;
int add = 0;
for ( int i=0; i<=n; i+=1){
if(i<=1){
add= i;
}else{
add = first+second;
first = second;
second = add;
}
} printf("fibonacci is:%d",add);
printf("\n");
}
int fibo(int n){
if(n==0){
return 0;
}
if(n==1){
return 1;
}
int fib1 = fibo(n-1);
int fib2 = fibo(n-2);
int fib = fib1+fib2;
// printf("fibonacci of %d is: %d\n",n,fibo);
return fib;
}
int GeneratePercentage(int since, int math, int history){ //..This is also another problem's solution functioni.
int addition = since+math+history;
int divide = addition/3;
int multiplication_f = divide;
return multiplication_f;
}
//one more same problem of recursion;
int fact(int x){
if(x==1){
return 1;
}
int fact_o_m1 = fact(x-1);
int actual_fact = fact_o_m1*x;
return actual_fact;
}
float convertTem(float celsius){ //.......this is also a question for practice
int farhenite = celsius*(9.0/5.0 )+ 32;
return farhenite;
}
int sum(int n){
if(n==1){
return 1;
}
int Sum_o_n_1 = sum(n-1);
int sum_of_N = Sum_o_n_1+n;
return sum_of_N;
}
void P_hello(int count){
if(count == 0){
return;
}
printf("Hello world\n");
P_hello(count-1);
}