• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Mar 25th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2.
3. long tribonacci (int n) {
4.     if (n<2) return 0;
5.     else if (n==2) return 1;
6.     else return
7.           tribonacci(n-1)
8.         + tribonacci(n-2)
9.         + tribonacci(n-3);
10. }
11. int coil(int a) {
12.     if (a<=0)
13.         return 0;
14.     else return a + coil(a - 2);
15. }
16.
17. double carpet(double field, int recursion) {
18.     if (recursion == 0) return field * 8.0/9.0;
19.     else return carpet(field * 8.0/9.0, recursion - 1);
20. }
21.
22.
23. int main(void) {
24.     int n;
25.     scanf("%d", &n);
26.     printf("%d\n", tribonacci(n));
27.
28.
29.
30.     int a;
31.     scanf("%d", &a);
32.     printf("%d\n", coil(a));
33.
34.
35.     int recursion;
36.     double field;
37.     scanf("%d", &recursion);
38.     scanf("%lf", &field);
39.
40.     printf("%d, %lf\n", recursion, field);
41.
42.     printf("%lf\n", carpet(field, recursion));
43. }
44.
45. #include <stdio.h>
46. #define SIZE 10
47.
48.
49. int ar[SIZE];
50. int top1 = -1;
51. int top2 = SIZE;
52.
53. //Functions to push data
54. void push_stack1 (int data)
55. {
56.   if (top1 < top2 - 1)
57.   {
58.     ar[++top1] = data;
59.   }
60.   else
61.   {
62.     printf ("Stack Full! Cannot Push\n");
63.   }
64. }
65. void push_stack2 (int data)
66. {
67.   if (top1 < top2 - 1)
68.   {
69.     ar[--top2] = data;
70.   }
71.   else
72.   {
73.     printf ("Stack Full! Cannot Push\n");
74.   }
75. }
76.
77. //Functions to pop data
78. void pop_stack1 ()
79. {
80.   if (top1 >= 0)
81.   {
82.     int popped_value = ar[top1--];
83.     printf ("%d is being popped from Stack 1\n", popped_value);
84.   }
85.   else
86.   {
87.     printf ("Stack Empty! Cannot Pop\n");
88.   }
89. }
90. void pop_stack2 ()
91. {
92.   if (top2 < SIZE)
93.   {
94.     int popped_value = ar[top2++];
95.     printf ("%d is being popped from Stack 2\n", popped_value);
96.   }
97.   else
98.   {
99.     printf ("Stack Empty! Cannot Pop\n");
100.   }
101. }
102.
103. //Functions to Print Stack 1 and Stack 2
104. void print_stack1 ()
105. {
106.   int i;
107.   for (i = top1; i >= 0; --i)
108.   {
109.     printf ("%d ", ar[i]);
110.   }
111.   printf ("\n");
112. }
113. void print_stack2 ()
114. {
115.   int i;
116.   for (i = top2; i < SIZE; ++i)
117.   {
118.     printf ("%d ", ar[i]);
119.   }
120.   printf ("\n");
121. }
122.
123. int main()
124. {
125.   int ar[SIZE];
126.   int i;
127.   int num_of_ele;
128.
129.   printf ("We can push a total of 10 values\n");
130.
131.   //Number of elements pushed in stack 1 is 6
132.   //Number of elements pushed in stack 2 is 4
133.
134.   for (i = 1; i <= 6; ++i)
135.   {
136.     push_stack1 (i);
137.     printf ("Value Pushed in Stack 1 is %d\n", i);
138.   }
139.   for (i = 1; i <= 4; ++i)
140.   {
141.     push_stack2 (i);
142.     printf ("Value Pushed in Stack 2 is %d\n", i);
143.   }
144.
145.   //Print Both Stacks
146.   print_stack1 ();
147.   print_stack2 ();
148.
149.   //Pushing on Stack Full
150.   printf ("Pushing Value in Stack 1 is %d\n", 11);
151.   push_stack1 (11);
152.
153.   //Popping All Elements From Stack 1
154.   num_of_ele = top1 + 1;
155.   while (num_of_ele)
156.   {
157.     pop_stack1 ();
158.     --num_of_ele;
159.   }
160.
161.   //Trying to Pop From Empty Stack
162.   pop_stack1 ();
163.
164.   return 0;
165. }
166.
167. #include <stdio.h>
168.
169. int MAXSIZE = 8;
170. int stack;
171. int top = -1;
172.
173. int isempty() {
174.
175.    if(top == -1)
176.       return 1;
177.    else
178.       return 0;
179. }
180.
181. int isfull() {
182.
183.    if(top == MAXSIZE)
184.       return 1;
185.    else
186.       return 0;
187. }
188.
189. int peek() {
190.    return stack[top];
191. }
192.
193. int pop() {
194.    int data;
195.
196.    if(!isempty()) {
197.       data = stack[top];
198.       top = top - 1;
199.       return data;
200.    } else {
201.       printf("Could not retrieve data, Stack is empty.\n");
202.    }
203. }
204.
205. int push(int data) {
206.
207.    if(!isfull()) {
208.       top = top + 1;
209.       stack[top] = data;
210.    } else {
211.       printf("Could not insert data, Stack is full.\n");
212.    }
213. }
214.
215. int main() {
216.    // push items on to the stack
217.    push(3);
218.    push(5);
219.    push(9);
220.    push(1);
221.    push(12);
222.    push(15);
223.
224.    printf("Element at top of the stack: %d\n" ,peek());
225.    printf("Elements: \n");
226.
227.    // print stack data
228.    while(!isempty()) {
229.       int data = pop();
230.       printf("%d\n",data);
231.    }
232.
233.    printf("Stack full: %s\n" , isfull()?"true":"false");
234.    printf("Stack empty: %s\n" , isempty()?"true":"false");
235.
236.    return 0;
237. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?