about summary refs log tree commit diff stats
path: root/org/c/ex_03.org
diff options
context:
space:
mode:
Diffstat (limited to 'org/c/ex_03.org')
-rw-r--r--org/c/ex_03.org47
1 files changed, 47 insertions, 0 deletions
diff --git a/org/c/ex_03.org b/org/c/ex_03.org
new file mode 100644
index 0000000..b889a2c
--- /dev/null
+++ b/org/c/ex_03.org
@@ -0,0 +1,47 @@
+* Exercise 3
+
+#+BEGIN_SRC C
+    #include <stdio.h>
+
+  int main()
+    {
+      int age = 10;
+      int height = 72;
+
+      printf("I am %d years old.\n", age);
+      printf("I am %d inches tall.\n", height);
+
+      return 0;
+    }
+#+END_SRC
+
+#+RESULTS:
+| I | am | 10 | years  | old.  |
+| I | am | 72 | inches | tall. |
+
+** printf conversion specifiers
+
++ %%,	Print a single % character
++ %c,	Convert an int to an unsigned character and print the resulting character
++ %d or %i,	Print an int as a signed decimal number
++ %u,	Print an unsigned as an unsigned decimal number
++ %o,	Print an unsigned as an unsigned octal number
++ %x,	Hexadecimal notation (using lowercase letters a-f)
++ %X,	Hexadecimal notation (using uppercase letters A-F)
++ %e,	Exponential notation (using a lowercase e as in 3.1415e+00)
++ %E,	Exponential notation (using an uppercase E as in 3.1415E+00)
++ %f,	Print a double using a decimal format like [-]ddd.ddd
++ %g,	The more compact of %e or %f, insignificant zeros do not print.
++ %G,	Same as g, but using an uppercase E
++ %s,	Print the string pointed to by a char *
++ %p,	Print a void * argument in hexadecimal (ANSI C only)
++ %n,	Store the number of characters printed at this point in the integer pointed to by the int * argument. Nothing is printed. (ANSI C only).
+
+** printf escape sequences
+
++ \n,	prints a new line
++ \b,	backs up one character
++ \t,	moves the output position to the next tab stop
++ \\,	prints a backslash
++ \",	prints a double quote
++ \',	prints a single quote