From 4b3b97e04baa266133be76d8e522e367b7890c48 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 11 Dec 2018 21:53:43 +0100 Subject: [PATCH] c/char,conditions --- in/public/code/c/index.rst | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/in/public/code/c/index.rst b/in/public/code/c/index.rst index d0e739f..9ada5f1 100644 --- a/in/public/code/c/index.rst +++ b/in/public/code/c/index.rst @@ -19,7 +19,29 @@ Input .. code:: c int entry1 = 0; + char operator; int entry2 = 0; printf("type in 2 integers\n"); - scanf("%d%d", &entry1, &entry2); + scanf("%d%s%d", &entry1, &operator, &entry2); printf("sum: %d\n", entry1 + entry2); + +Conditions +---------- + +.. code:: c + + if (condition) { + expression1; + } else { + expression2; + } + +.. code:: c + + switch (operator) { + case '+': + expression1; + break; + default: + printf("Nope!\n"); + }