C: различия между версиями
Перейти к навигации
Перейти к поиску
| Строка 11: | Строка 11: | ||
double d = 100.3; | double d = 100.3; | ||
bool busy = true; | bool busy = true; | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Ввод и вывод == | ||
| + | <syntaxhighlight lang="c#" line> | ||
| + | int age; | ||
| + | printf("Please, enter your age:"); | ||
| + | scanf_s("%d", &age); | ||
| + | printf("Your age = %d", age); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Условный оператор == | ||
| + | <syntaxhighlight lang="c#" line> | ||
| + | Console.WriteLine("Please, enter your age:"); | ||
| + | string ageString = Console.ReadLine(); | ||
| + | int age = Convert.ToInt32(ageString); | ||
| + | if (age > 65) | ||
| + | { | ||
| + | printf("Here is your pension."); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | printf("Good morning people!"); | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Циклы == | ||
| + | <syntaxhighlight lang="c#" line> | ||
| + | printf("while loop\n"); | ||
| + | int i = 1; | ||
| + | while (i < 11) | ||
| + | { | ||
| + | printf("%d\n", i); | ||
| + | i++; | ||
| + | } | ||
| + | |||
| + | printf("do while loop\n"); | ||
| + | i = 1; | ||
| + | do | ||
| + | { | ||
| + | printf("%d\n", i); | ||
| + | i++; | ||
| + | } while (i < 11); | ||
| + | |||
| + | printf("for loop\n"); | ||
| + | for (int j = 1; j < 11; j++) | ||
| + | { | ||
| + | printf("%d\n", j); | ||
| + | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Версия 12:09, 23 ноября 2020
Hello World
Объявление переменных
1 int i, j, k = 10;
2 char c, ch = 'a';
3 float f, salary = 4.5f;
4 double d = 100.3;
5 bool busy = true;
Ввод и вывод
1 int age;
2 printf("Please, enter your age:");
3 scanf_s("%d", &age);
4 printf("Your age = %d", age);
Условный оператор
1 Console.WriteLine("Please, enter your age:");
2 string ageString = Console.ReadLine();
3 int age = Convert.ToInt32(ageString);
4 if (age > 65)
5 {
6 printf("Here is your pension.");
7 }
8 else
9 {
10 printf("Good morning people!");
11 }
Циклы
1 printf("while loop\n");
2 int i = 1;
3 while (i < 11)
4 {
5 printf("%d\n", i);
6 i++;
7 }
8
9 printf("do while loop\n");
10 i = 1;
11 do
12 {
13 printf("%d\n", i);
14 i++;
15 } while (i < 11);
16
17 printf("for loop\n");
18 for (int j = 1; j < 11; j++)
19 {
20 printf("%d\n", j);
21 }