2018-12-11 20:38:01 +00:00
|
|
|
C
|
|
|
|
=
|
|
|
|
|
|
|
|
Main
|
|
|
|
----
|
|
|
|
|
|
|
|
.. code:: c
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
main() {
|
|
|
|
printf("Hello, world!\n");
|
|
|
|
system("pause");
|
|
|
|
}
|
2018-12-11 20:43:19 +00:00
|
|
|
|
2018-12-11 20:56:47 +00:00
|
|
|
Declarations
|
|
|
|
------------
|
2018-12-11 20:43:19 +00:00
|
|
|
|
|
|
|
.. code:: c
|
|
|
|
|
2018-12-11 20:53:43 +00:00
|
|
|
char operator;
|
2018-12-11 20:56:47 +00:00
|
|
|
int entry1 = 0;
|
2018-12-11 20:43:19 +00:00
|
|
|
int entry2 = 0;
|
2018-12-11 20:56:47 +00:00
|
|
|
long entry = 0;
|
|
|
|
|
|
|
|
Input
|
|
|
|
-----
|
|
|
|
|
|
|
|
.. code:: c
|
|
|
|
|
2018-12-11 20:43:19 +00:00
|
|
|
printf("type in 2 integers\n");
|
2018-12-11 20:53:43 +00:00
|
|
|
scanf("%d%s%d", &entry1, &operator, &entry2);
|
2018-12-11 20:43:19 +00:00
|
|
|
printf("sum: %d\n", entry1 + entry2);
|
2018-12-11 20:53:43 +00:00
|
|
|
|
|
|
|
Conditions
|
|
|
|
----------
|
|
|
|
|
|
|
|
.. code:: c
|
|
|
|
|
|
|
|
if (condition) {
|
|
|
|
expression1;
|
|
|
|
} else {
|
|
|
|
expression2;
|
|
|
|
}
|
|
|
|
|
|
|
|
.. code:: c
|
|
|
|
|
|
|
|
switch (operator) {
|
|
|
|
case '+':
|
|
|
|
expression1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Nope!\n");
|
|
|
|
}
|
2018-12-11 20:56:47 +00:00
|
|
|
|
|
|
|
Loops
|
|
|
|
-----
|
|
|
|
|
|
|
|
.. code:: c
|
|
|
|
|
|
|
|
while (condition) {
|
|
|
|
expression1;
|
|
|
|
}
|