Beruflich Dokumente
Kultur Dokumente
h>
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int x,y,sum;
float average;
cout << "Enter 2 integers : " << endl;
cin>>x>>y;
sum=x+y;
average=sum/2;
cout << "The sum of " << x << " and " << y << " is " << sum << "." << endl;
cout << "The average of " << x << " and " << y << " is " << average << "."
<< endl;
getch();
}
This program takes in two integers x and y as a screen input from the user.
The sum and average of these two integers are calculated and outputted
using the 'cout' command.
1.
/*
2.
3.
4.
*/
5.
#include <stdio.h>
6.
#define MAXSIZE 10
7.
8.
void main()
9.
10.
int array[MAXSIZE];
11.
12.
13.
14.
scanf("%d", &num);
15.
16.
17.
18.
scanf("%d", &array[i]);
19.
20.
21.
22.
23.
printf("%d\n", array[i]);
24.
25.
26.
27.
28.
29.
30.
31.
32.
temp = array[j];
33.
34.
array[j + 1] = temp;
35.
36.
37.
38.
39.
40.
41.
printf("%d\n", array[i]);
42.
43.
}
44.
/*
45.
46.
47.
*/
48.
#include <stdio.h>
49.
#include <malloc.h>
50.
51.
void main()
52.
53.
int i, n, sum = 0;
54.
int *a;
55.
56.
57.
scanf("%d", &n);
58.
59.
60.
61.
62.
scanf("%d", a + i);
63.
64.
65.
66.
67.
68.
69.
70.
71.
* C Program to find the nth number in Fibonacci series using recursion
72.
*/
73.
#include <stdio.h>
74.
int fibo(int);
75.
76.
int main()
77.
78.
int num;
79.
int result;
80.
81.
82.
scanf("%d", &num);
83.
if (num < 0)
84.
85.
86.
87.
else
88.
89.
result = fibo(num);
90.
91.
92.
return 0;
93.
94.
95.
96.
if (num == 0)
97.
98.
return 0;
99.
100.
else if (num == 1)
101.
102.
return 1;
103.
104.
else
105.
106.
107.
108. }
109. *
int stk[MAXSIZE];
120.
int top;
121. };
122. typedef struct stack STACK;
123. STACK s;
124.
125. void push(void);
126. int pop(void);
127. void display(void);
128.
129. void main ()
130. {
131.
int choice;
132.
int option = 1;
133.
s.top = -1;
134.
135.
136.
while (option)
137.
138.
printf ("------------------------------------------\n");
139.
printf ("
-->
PUSH
140.
printf ("
-->
POP
141.
printf ("
-->
DISPLAY
142.
printf ("
-->
EXIT
143.
printf ("------------------------------------------\n");
\n");
\n");
\n");
\n");
144.
145.
146.
scanf
147.
switch (choice)
148.
149.
case 1:
150.
("%d", &choice);
push();
151.
break;
152.
case 2:
153.
pop();
154.
break;
155.
case 3:
156.
display();
157.
break;
158.
case 4:
159.
return;
160.
161.
fflush (stdin);
162.
163.
164.
scanf
("%d", &option);
165. }
166. /* Function to add an element to the stack */
167. void push ()
168. {
169.
int num;
170.
171.
172.
173.
return;
174.
175.
else
176.
177.
178.
179.
s.top = s.top + 1;
180.
s.stk[s.top] = num;
181.
182.
return;
183. }
184. /* Function to delete an element from the stack */
185. int pop ()
186. {
187.
int num;
188.
if (s.top == - 1)
189.
190.
191.
return (s.top);
192.
193.
else
194.
195.
num = s.stk[s.top];
196.
197.
s.top = s.top - 1;
198.
199.
return(num);
200. }
201. /* Function to display the status of the stack */
202. void display ()
203. {
204.
int i;
205.
if (s.top == -1)
206.
207.
208.
return;
209.
210.
else
211.
212.
213.
214.
215.
216.
217.
218.
printf ("\n");
219. }