Advertisement
l4cky

Untitled

Feb 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "functions.h"
  6.  
  7. int main (int argc, char *argv[])
  8. {
  9. char buffer[20];
  10. int amount, count, N, Delitel, AmountPrimeNumber;
  11. int ArrayInt[count];
  12. // Приветствие
  13. printf("Приветствие\n");
  14.  
  15. //-------------------------------------------
  16.  
  17. // Некорректный ввод
  18. if (argc < 3)
  19. {
  20. printf("Неправильный ввод данных!\n");
  21. printf("Для корректного ввода требуется ввести ./mass hand 4 или ./mass auto 8\n");
  22. exit(0);
  23. }
  24.  
  25. //-------------------------------------------
  26.  
  27. {
  28. char buffer [20];
  29. int count;
  30. int ArrayInt[amount];
  31. for (count = 0; count < amount; count++)
  32. {
  33. printf ("ArrayInt[%d] = ", count);
  34. fgets( buffer, 18, stdin );
  35. ArrayInt[count] = atoi(buffer);
  36. }
  37. }
  38.  
  39. //-------------------------------------------
  40.  
  41.  
  42. //Ввод массива вручную
  43. if (strcmp( argv[1], "hand" ) == 0 )
  44. {
  45.  
  46. //запрос количество элементов
  47. int ArrayInt[amount];
  48. amount = atoi(argv[2]);
  49.  
  50. if (amount < 2 || amount > 35)
  51. {
  52. printf("Количество элементов в массиве не должно быть меньше 2 и не больше 35! Попробуйте еще раз.\n");
  53. exit(0);
  54. }
  55. /*
  56. if (amount < 2)
  57. {
  58. printf("Количество элементов в массиве не должно быть меньше двух! Попробуйте еще раз.\n");
  59. exit(0);
  60. }
  61.  
  62. if (amount > 35)
  63. {
  64. printf("Количество элементов слишком много, количиство элементов должно быть менее 35! Попробуйте еще раз.\n");
  65. exit(0);
  66. }
  67. */
  68.  
  69. //заполнение массива вручную
  70. for ( count = 0; count < amount; count++ )
  71. {
  72. printf("AmountInt[%d] = ", count);
  73. fgets( buffer, 18, stdin );
  74. ArrayInt[count] = atoi(buffer);
  75. }
  76.  
  77. //вывод массива
  78. ArrayInt[count] = atoi(buffer);
  79. printf ("Введенный массив: ");
  80. for ( count = 0; count < amount; count++ )
  81. {
  82. printf("%d ", ArrayInt[count]);
  83. }
  84. printf("\n");
  85.  
  86. //проверка на простые числа и вывод
  87. printf ("Массив из простых чисел: ");
  88. AmountPrimeNumber = 0;
  89. for ( count = 0; count < amount; count++ )
  90. {
  91. if ( PrimeNumber(ArrayInt[count]) )
  92. printf ( "%d ", ArrayInt[count] );
  93. }
  94. }
  95.  
  96. //-------------------------------------------
  97.  
  98. //Ввод массива автоматически
  99.  
  100. if ( strcmp( argv[1], "auto" ) == 0 )
  101. {
  102.  
  103. //запрос количество элементов
  104. int ArrayInt[amount];
  105. amount = atoi(argv[2]);
  106.  
  107. if (amount < 2 || amount > 35)
  108. {
  109. printf("Количество элементов в массиве не должно быть меньше 2 и не больше 35! Попробуйте еще раз.\n");
  110. exit(0);
  111. }
  112.  
  113. //заполнение массива автоматически
  114. srand(time(NULL));
  115. for ( count = 0; count < amount; count++ )
  116. {
  117. ArrayInt[count] = rand()%100;
  118. }
  119.  
  120. //вывод массива
  121. printf ("Введенный массив: ");
  122. for ( count = 0; count < amount; count++ )
  123. {
  124. printf("%d ", ArrayInt[count]);
  125. }
  126. printf("\n");
  127.  
  128.  
  129. //проверка на простые числа и вывод
  130. printf ("Массив из простых чисел: ");
  131. AmountPrimeNumber = 0;
  132. for ( count = 0; count < amount; count++ )
  133. {
  134. if ( PrimeNumber(ArrayInt[count]) )
  135. printf ( "%d ", ArrayInt[count] );
  136. }
  137. printf("\n");
  138. }
  139.  
  140. //-------------------------------------------
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement