Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Доделать. Найти ошибку
- #include <stdio.h>
- #include <stdlib.h>
- int prime_number(int n);
- int arr[123];
- void monitor();
- int foo();
- ///////////////////////////////////////////////////////
- int main() //
- {
- printf("Initial check of the \"prime_number()\" function: \n");
- printf(" - - - - - - - - - - - - - - - - \n");
- for(int i = 1; i < 30; i ++)
- {
- if(prime_number(i) == 1)
- printf("%3d this is a prime number \n", i);
- } printf(" \n" );
- srand(7);
- for(int i = 0; i < 123; i++)
- {
- arr[i] = rand();
- }
- monitor();
- for(int i = 0; i < 123; i++)
- {
- if(prime_number(arr[i]) == 0) arr[i] = 0;
- }
- monitor();
- //while(foo());
- foo();
- printf("\n");
- monitor();
- return 0;
- }
- /////////////////////////////////////////////////////////
- void monitor()
- {
- int cnt = 0;
- for(int i = 0; i < 123; i++)
- {
- printf("%5d, ", arr[i]);
- if(cnt++ > 9) { cnt = 0; printf("\n"); }
- }
- printf("\n");
- }
- /////////////////////////////////////////////////////////
- int prime_number(int n) //
- {
- if(n <= 1) return 0;
- for(int i = 2; i < n; i++)
- {
- if(n%i == 0) return 0;
- }
- return 1;
- }
- //////////////////////////////////////////////////////////
- int foo()
- {
- int n;
- int i = 0;
- for(; i < 123; i++)
- {
- if(arr[i] == 0)
- {
- n = i;
- break;
- }
- }
- for(; i < 123; i++)
- {
- if(arr[i] != 0)
- {
- arr[n] = arr[i];
- arr[0] = 0;
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement