Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <math.h>
- int prime(int *tomb, int db)
- {
- int i, j, primszam=1;
- for(i=0;i<db;i++)
- {
- if(tomb[i]<2)
- primszam++;
- for(j=2;j<sqrt(tomb[i]);j++)
- {
- if(tomb[i]%j == 0)
- {
- return 0;
- }
- }
- }
- if(primszam == 1)
- return 1;
- else
- return 0;
- }
- int main()
- {
- int i, db;
- char sor[10000];
- int szamtomb[1000];
- char *p;
- while(1){
- gets(sor);
- p = strtok(sor," \n");
- db = atoi(p);
- if(db==0) break;
- for(i=0;i<db;i++)
- {
- p = strtok(NULL, " \n");
- szamtomb[i]=atoi(p);
- }
- printf(prime(szamtomb, db)==1 ? "YES\n" : "NO\n");
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment