Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "functions.h"
- int main (int argc, char *argv[])
- {
- char buffer[20];
- int amount, count, N, Delitel, AmountPrimeNumber;
- int ArrayInt[count];
- // Приветствие
- printf("Приветствие\n");
- //-------------------------------------------
- // Некорректный ввод
- if (argc < 3)
- {
- printf("Неправильный ввод данных!\n");
- printf("Для корректного ввода требуется ввести ./mass hand 4 или ./mass auto 8\n");
- exit(0);
- }
- //-------------------------------------------
- {
- char buffer [20];
- int count;
- int ArrayInt[amount];
- for (count = 0; count < amount; count++)
- {
- printf ("ArrayInt[%d] = ", count);
- fgets( buffer, 18, stdin );
- ArrayInt[count] = atoi(buffer);
- }
- }
- //-------------------------------------------
- //Ввод массива вручную
- if (strcmp( argv[1], "hand" ) == 0 )
- {
- //запрос количество элементов
- int ArrayInt[amount];
- amount = atoi(argv[2]);
- if (amount < 2 || amount > 35)
- {
- printf("Количество элементов в массиве не должно быть меньше 2 и не больше 35! Попробуйте еще раз.\n");
- exit(0);
- }
- /*
- if (amount < 2)
- {
- printf("Количество элементов в массиве не должно быть меньше двух! Попробуйте еще раз.\n");
- exit(0);
- }
- if (amount > 35)
- {
- printf("Количество элементов слишком много, количиство элементов должно быть менее 35! Попробуйте еще раз.\n");
- exit(0);
- }
- */
- //заполнение массива вручную
- for ( count = 0; count < amount; count++ )
- {
- printf("AmountInt[%d] = ", count);
- fgets( buffer, 18, stdin );
- ArrayInt[count] = atoi(buffer);
- }
- //вывод массива
- ArrayInt[count] = atoi(buffer);
- printf ("Введенный массив: ");
- for ( count = 0; count < amount; count++ )
- {
- printf("%d ", ArrayInt[count]);
- }
- printf("\n");
- //проверка на простые числа и вывод
- printf ("Массив из простых чисел: ");
- AmountPrimeNumber = 0;
- for ( count = 0; count < amount; count++ )
- {
- if ( PrimeNumber(ArrayInt[count]) )
- printf ( "%d ", ArrayInt[count] );
- }
- }
- //-------------------------------------------
- //Ввод массива автоматически
- if ( strcmp( argv[1], "auto" ) == 0 )
- {
- //запрос количество элементов
- int ArrayInt[amount];
- amount = atoi(argv[2]);
- if (amount < 2 || amount > 35)
- {
- printf("Количество элементов в массиве не должно быть меньше 2 и не больше 35! Попробуйте еще раз.\n");
- exit(0);
- }
- //заполнение массива автоматически
- srand(time(NULL));
- for ( count = 0; count < amount; count++ )
- {
- ArrayInt[count] = rand()%100;
- }
- //вывод массива
- printf ("Введенный массив: ");
- for ( count = 0; count < amount; count++ )
- {
- printf("%d ", ArrayInt[count]);
- }
- printf("\n");
- //проверка на простые числа и вывод
- printf ("Массив из простых чисел: ");
- AmountPrimeNumber = 0;
- for ( count = 0; count < amount; count++ )
- {
- if ( PrimeNumber(ArrayInt[count]) )
- printf ( "%d ", ArrayInt[count] );
- }
- printf("\n");
- }
- //-------------------------------------------
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement