-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise.html
273 lines (238 loc) · 9.11 KB
/
exercise.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Coding Exercises with Solutions - vCode">
<title>vCode</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/night-owl.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@300;400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./exercise.css">
<script src="https://kit.fontawesome.com/f0235048b7.js" crossorigin="anonymous"></script>
</head>
<body>
<!-- Navbar -->
<section id="navbar">
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="./index.html">vCode</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<!-- <li class="nav-item">
<a class="nav-link" href="#">About</a>
</li> -->
<li class="nav-item">
<a class="nav-link" href="/vcode/AssignmentOneJava.html">Assignment</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/vcode/jdbc.html"
>JDBC</a
>
</li>
</ul>
</div>
</div>
</nav>
</section>
<section class="hero-section container">
<h2 class="text-center mt-3 herotxt">C Exercise with Solutions</h2>
<div class="links">
<a href="#first">1. How to print Hello World in C ?</a>
<a href="#second">2. How to add two numbers in C ?</a>
<a href="#third">3. How to subtract two numbers in C ?</a>
<a href="#fourth">4. How to multiply two numbers in C ?</a>
<a href="#fifth">5. How to divide two numbers in C ?</a>
<a href="#sixth">6. How to find modulos of two numbers in C ?</a>
<a href="#seventh">7. How to convert temperature from Fahrenheit to Celsius in C ?</a>
<a href="#eighth">8. How to convert temperature from Celsius to Fahrenheit in C ?</a>
<a href="#ninth">9. How to calculate the area of a circle ?</a>
<a href="#tenth">10. Modify the same program of Q. 9 to calculate the volume of a cylinder.</a>
</div>
</section>
<section class="solutions container">
<h5 id="first">1. How to print Hello World in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
printf("Hello World !\n");
return 0;
} </code>
</pre>
</div>
<h5 id="second">2. How to add two numbers in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter first number:\n");
scanf("%d", &num1);
printf("Enter second number:\n");
scanf("%d", &num2);
int sum = num1 + num2;
printf("Sum is %d.\n", sum);
return 0;
} </code>
</pre>
</div>
<h5 id="third">3. How to subtract two numbers in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter first number:\n");
scanf("%d", &num1);
printf("Enter second number:\n");
scanf("%d", &num2);
int difference = num1 - num2;
printf("Difference is %d.\n", difference);
return 0;
} </code>
</pre>
</div>
<h5 id="fourth">4. How to multiply two numbers in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter first number:\n");
scanf("%d", &num1);
printf("Enter second number:\n");
scanf("%d", &num2);
int multiply = num1 * num2;
printf("Product is %d.\n", multiply);
return 0;
} </code>
</pre>
</div>
<h5 id="fifth">5. How to divide two numbers in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter first number:\n");
scanf("%d", &num1);
printf("Enter second number:\n");
scanf("%d", &num2);
int division = num1 / num2;
printf("Result is %d.\n", division);
return 0;
} </code>
</pre>
</div>
<h5 id="sixth">6. How to find modulos of two numbers in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter first number:\n");
scanf("%d", &num1);
printf("Enter second number:\n");
scanf("%d", &num2);
int modulos = num1 % num2;
printf("Result is %d.\n", modulos);
return 0;
} </code>
</pre>
</div>
<h5 id="seventh">7. How to convert temperature from Fahrenheit to Celsius in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
float temperatureInFahrenheit, temperatureInCelsius;
printf("Enter the temperature in Fahrenheit:\n");
scanf("%f", &temperatureInFahrenheit);
temperatureInCelsius = (temperatureInFahrenheit - 32) / 1.8;
printf("Temperature in Celsius: %.2f\n", temperatureInCelsius);
return 0;
} </code>
</pre>
</div>
<h5 id="eighth">8. How to convert temperature from Celsius to Fahrenheit in C ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
float temperatureInFahrenheit, temperatureInCelsius;
printf("Enter the temperature in Celsius:\n");
scanf("%f", &temperatureInCelsius);
temperatureInFahrenheit = (temperatureInCelsius * 9/5) + 32;
printf("Temperature in Fahrenheit: %.1f\n", temperatureInFahrenheit);
return 0;
} </code>
</pre>
</div>
<h5 id="ninth">9. How to calculate the area of a circle ?</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
float pie = 3.14;
float radius;
printf("Enter the radius of the circle:\n");
scanf("%f", &radius);
float areaOfCircle = (pie * radius * radius);
printf("Area of the circle: %.2f\n", areaOfCircle);
return 0;
} </code>
</pre>
</div>
<h5 id="tenth">10. Modify the same program of Q. 9 to calculate the volume of a cylinder.</h5>
<div class="container">
<pre class="box">
<code class="c">#include <stdio.h>
int main()
{
float pie = 3.14;
float radius;
printf("Enter the radius of the circle:\n");
scanf("%f", &radius);
float areaOfCircle = (pie * radius * radius);
printf("Area of the circle: %.2f\n", areaOfCircle);
float height;
printf("Enter the height of the cylinder:\n");
scanf("%f", &height);
float volumeOfCylinder = (pie * radius * radius * height);
printf("Volume of the cylinder: %.2f\n", volumeOfCylinder);
return 0;
} </code>
</pre>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>