Advertisement
80LK

LR17 AKT

Nov 5th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.29 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4.  
  5. void quest1();
  6. void quest2();
  7. void quest3();
  8. void quest4();
  9. void quest5();
  10.  
  11. int main()
  12. {
  13.     setlocale(0, ".1251");
  14.  
  15.     while (1)
  16.         quest2();
  17. }
  18.  
  19. void quest1(){
  20.     float a, b;
  21.  
  22.     do {
  23.         printf("Расстояние до дачи(КМ): ");
  24.         scanf_s("%f", &a);
  25.        
  26.         if (a <= 0)
  27.             puts("Не корректные данные.");
  28.  
  29.     } while (a <= 0);
  30.    
  31.     b = a / 100;
  32.  
  33.     do {
  34.         printf("Кол-во топлива затраченного на 100км: ");
  35.         scanf_s("%f", &a);
  36.  
  37.         if (a <= 0)
  38.             puts("Не корректные данные.");
  39.  
  40.     } while (a <= 0);
  41.  
  42.     b *= a;
  43.  
  44.     do {
  45.         printf("Цена за литр топлива: ");
  46.         scanf_s("%f", &a);
  47.  
  48.         if (a <= 0)
  49.             puts("Не корректные данные.");
  50.  
  51.     } while (a <= 0);
  52.  
  53.     b *= a;
  54.  
  55.     printf("Стоимость поездки на дачу: %.2f\n", b);
  56. }
  57.  
  58. void quest2() {
  59.     int m, n, l = 0;
  60.    
  61.     printf("Введите M:");
  62.     scanf_s("%d", &m);
  63.  
  64.     printf("Введите N:");
  65.     scanf_s("%d", &n);
  66.  
  67.     if (m > n) {
  68.         m += n;
  69.         n = m - n;
  70.         m -= n;
  71.     }
  72.    
  73.     printf("Числа, сумма цифр которых = 12: ");
  74.  
  75.     for (int i = m; i <= n; i++) {
  76.         int s = 0, x = i;
  77.         do {
  78.             s += x%10;
  79.             x /= 10;
  80.         } while (x != 0);
  81.  
  82.         if (s == 12) {
  83.             if (l != 0)
  84.                 printf(", ");
  85.  
  86.             printf("%d", i);
  87.             l++;
  88.         }
  89.     }
  90.  
  91.  
  92.     if (l == 0)
  93.         printf("Таких чисел нет.");
  94.  
  95.     puts("");
  96. }
  97.  
  98. void quest3() {
  99.     int n, i = 0;
  100.     float s = 0;
  101.  
  102.     do {
  103.         printf("Введите число: ");
  104.         scanf_s("%d", &n);
  105.  
  106.         if (n == 0) {
  107.             if(i == 0)
  108.                 printf("Последовательность не задана.");
  109.  
  110.         } else {
  111.             i++;
  112.             s += n;
  113.         }
  114.            
  115.     } while (n != 0 || i == 0);
  116.  
  117.     s /= i;
  118.     printf("Среднее значение: %.2f\n", s);
  119. }
  120.  
  121. void quest4(){
  122.     int s, i;
  123.     float *arr, n;
  124.  
  125.     do {
  126.         printf("Размер массива: ");
  127.         scanf_s("%d", &s);
  128.     } while (s < 1);
  129.  
  130.     arr = (float*)calloc(s, sizeof(float));
  131.  
  132.     for (int i = 0; i < s; i++) {
  133.         printf("A[%d] = ", i + 1);
  134.         scanf_s("%f", &arr[i]);
  135.     }
  136.  
  137.     printf("Введите число: ");
  138.     scanf_s("%f", &n);
  139.  
  140.     for (int i = 0; i < s; i++)
  141.         printf("%.2f\t", arr[i]);
  142.  
  143.     puts("");
  144.  
  145.     for (i = 0; i < s; i++)
  146.         if (n == arr[i]) {
  147.             puts("Число входит в массив");
  148.             break;
  149.         }
  150.    
  151.     if(i == s)
  152.         puts
  153. ("Число не входит в массив");
  154. }
  155.  
  156. void quest5() {
  157.     srand(time(NULL));
  158.     int **arr, n, m, max;
  159.    
  160.     do {
  161.         printf("Кол-во строк: ");
  162.         scanf_s("%d", &n);
  163.     } while (n < 1);
  164.  
  165.     arr = (int**)calloc(n, sizeof(int*));
  166.  
  167.     do {
  168.         printf("Кол-во столбцов: ");
  169.         scanf_s("%d", &m);
  170.     } while (m < 1);
  171.    
  172.     for (int i = 0; i < n; i++) {
  173.         arr[i] = (int*)calloc(m, sizeof(int));
  174.         for (int j = 0; j < m; j++) {
  175.             arr[i][j] = rand()%101-50;
  176.             if (j == 0 || arr[i][j] > max)
  177.                 max = arr[i][j];
  178.         }
  179.         printf("Максимальное значение стррки %d: %d\n", i+1, max);
  180.     }
  181.  
  182.  
  183.  
  184.     for (int i = -1; i < n; i++) {
  185.         if (i == -1)
  186.             printf("   Массив  |");
  187.         else
  188.             printf(" Строка %.2d |", i+1);
  189.  
  190.         for (int j = 0; j < m; j++) {
  191.             if (i == -1)
  192.                 printf(" Столбец %.2d |", j + 1);
  193.             else
  194.                 printf(" %10d |", arr[i][j]);
  195.         }
  196.         puts("");
  197.     }
  198.    
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement