C

Материал из Информационная безопасностя
Перейти к навигации Перейти к поиску

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 printf("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 }