Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- int paritate(int a){
- int s=0;
- while(a != 0){
- s=s+a%10;
- a=a/10;
- }
- if(s % 2 == 0)
- return 1;
- return 0;
- }
- int primaritate(int a){
- int i,ok=0;
- for(i=2;i<=a/2 && ok==0;i++)
- if(a % i == 0)
- ok=1;
- if(ok == 0)
- return 1;
- return 0;
- }
- using namespace std;
- int v[100],b[100];
- int main(){
- ifstream f1("atestat.in");
- ofstream f2("atestat.out");
- int n,x,i=0,j=0,c,d,aux;
- f1>>n;
- while(f1>>x){
- if(paritate(x) == 1){
- i++;
- v[i]=x;
- }
- if(primaritate(x) == 1){
- j++;
- b[j]=x;
- }
- }
- if(i == 0)
- f2<<"NU EXISTA";
- else{
- for(c=1;c<=i-1;c++)
- for(d=c+1;d<=i;d++)
- if(v[c] < v[d]){
- aux=v[c];
- v[c]=v[d];
- v[d]=aux;
- }
- for(c=1;c<=i;c++)
- f2<<v[c]<<" ";
- f2<<endl;
- }
- if(j == 0)
- f2<<"NU EXISTA";
- else{
- for(c=1;c<=j-1;c++)
- for(d=c+1;d<=j;d++)
- if(b[c] > b[d]){
- aux=b[c];
- b[c]=b[d];
- b[d]=aux;
- }
- for(c=1;c<=j;c++)
- f2<<b[c]<<" ";
- }
- }
Add Comment
Please, Sign In to add comment