We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d1fd565 commit 23545f0Copy full SHA for 23545f0
prog.4.5.c
@@ -0,0 +1,27 @@
1
+// Basic conversions in C
2
+
3
+#include <stdio.h>
4
5
+int main (void)
6
+{
7
+ float f1 = 123.125, f2;
8
+ int i1, i2 = -150;
9
+ char c = 'a';
10
11
+ i1 = f1; // floating to integer conversion
12
+ printf ("%f assigned to an int produces %i\n", f1, i1);
13
14
+ f1 = i2; // integer to floating conversion
15
+ printf ("%i assigned to an float produces %f\n", i2, f1);
16
17
+ f1 = i2 / 100; // integer divided by integer
18
+ printf ("%i divided by 100 produces %f\n", i2, f1);
19
20
+ f2 = i2 / 100.0; // integer divided by a float
21
+ printf ("%i divided by 100.0 produces %f\n", i2, f2);
22
23
+ f2 = (float) i2 / 100; // type cast operator
24
+ printf ("(float) %i divided by 100 produces %f\n", i2, f2);
25
26
+ return 0;
27
+}
0 commit comments