Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. void min_max()
  4. {int n,a[1001],i,min,max;
  5. cin>>n;
  6. for(i=1; i<=n; i++)
  7. cin>>a[i];
  8. min=a[1];
  9. max=a[1];
  10. for(i=1; i<=n; i++)
  11. {
  12. if(a[i]<min)
  13. min=a[i];
  14. if(a[i]>max)
  15. max=a[i];
  16. }
  17. cout<<min<<' '<<max<<'\n';
  18. }
  19. void suma_cifre()
  20.  
  21. {
  22. //suma cifrelor
  23. int x,S=0;
  24. cin>>x;
  25. while(x!=0)
  26. {
  27. S=S+x%10;
  28. x=x/10;
  29. }
  30. cout<<S;
  31.  
  32. }
  33. void oglindit()
  34. { //OGLINDITUL
  35. int x,o=0;
  36. cin>>x;
  37. while(x)
  38. {
  39. o=o*10+x%10;
  40. x=x/10;
  41. }
  42. cout<<o;
  43. }
  44. void palindtom()
  45. { //Palindrom
  46. int x,o=0,y;
  47. cin>>x;
  48. y=x;
  49. while(x)
  50. {
  51. o=o*10+x%10;
  52. x=x/10;
  53. }
  54. if(o==y)
  55. cout<<"PALINDROM";
  56. else
  57. cout<<"NU E PALINDROM";
  58. }
  59. void
  60.  
  61. int main()
  62. {
  63. int t;
  64. cin>>t;
  65. if(t==1) min_max();
  66. else if(t==2) suma_cifre();
  67. else if(t==3) oglindit();
  68. else if (t==4) palindtom();
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. { //ALGORITM EUCLID
  80. int a,b,r;
  81. cin>>a>>b;
  82. while(b!=0)
  83.  
  84. {
  85. r=a%b;
  86. a=b;
  87. b=r;
  88. }
  89. cout<<a;
  90. }
  91.  
  92. {
  93. //NUMAR PRIM
  94. int d,n,prim=1;
  95. cin>>n;
  96. for(d=2; d*d<=n; ++d)
  97. if(n%d==0)
  98. prim=0;
  99. if(prim)
  100. cout<<"NUMAR PRIM";
  101. else
  102. cout<<"NUMAR NEPRIM";
  103. }
  104.  
  105.  
  106. { //COMPUNEREA UNUI NUMAR DIN CIFRELE SALE
  107. int x=0,n,c,i;
  108. cin>>n;
  109. for(i=1; i<=n; ++i)
  110. {
  111. cin>>c;
  112. x=x*10+c;
  113. }
  114. cout<<x;
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement