alexon5519

28-programare

Feb 26th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. int paritate(int a){
  5. int s=0;
  6. while(a != 0){
  7. s=s+a%10;
  8. a=a/10;
  9. }
  10. if(s % 2 == 0)
  11. return 1;
  12. return 0;
  13. }
  14.  
  15. int primaritate(int a){
  16. int i,ok=0;
  17. for(i=2;i<=a/2 && ok==0;i++)
  18. if(a % i == 0)
  19. ok=1;
  20. if(ok == 0)
  21. return 1;
  22. return 0;
  23. }
  24.  
  25. using namespace std;
  26.  
  27. int v[100],b[100];
  28. int main(){
  29. ifstream f1("atestat.in");
  30. ofstream f2("atestat.out");
  31. int n,x,i=0,j=0,c,d,aux;
  32. f1>>n;
  33. while(f1>>x){
  34. if(paritate(x) == 1){
  35. i++;
  36. v[i]=x;
  37. }
  38. if(primaritate(x) == 1){
  39. j++;
  40. b[j]=x;
  41. }
  42. }
  43. if(i == 0)
  44. f2<<"NU EXISTA";
  45. else{
  46. for(c=1;c<=i-1;c++)
  47. for(d=c+1;d<=i;d++)
  48. if(v[c] < v[d]){
  49. aux=v[c];
  50. v[c]=v[d];
  51. v[d]=aux;
  52. }
  53. for(c=1;c<=i;c++)
  54. f2<<v[c]<<" ";
  55. f2<<endl;
  56. }
  57. if(j == 0)
  58. f2<<"NU EXISTA";
  59. else{
  60. for(c=1;c<=j-1;c++)
  61. for(d=c+1;d<=j;d++)
  62. if(b[c] > b[d]){
  63. aux=b[c];
  64. b[c]=b[d];
  65. b[d]=aux;
  66. }
  67. for(c=1;c<=j;c++)
  68. f2<<b[c]<<" ";
  69. }
  70. }
Add Comment
Please, Sign In to add comment