Advertisement
kalin729

Задача за контролното 7,12

Dec 6th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include<iostream>>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     double avg;
  7.     bool is_prime=true;
  8.     int a[100],n,sum=0,odd=0,even=0,min,max,product=1,moreavg,count=0,prnumb=0,qdrnumb=0,num_cpy;
  9.     cout << "Enter number count: ";
  10.     cin >> n;
  11.     moreavg = 0;
  12.     for (int i=0; i < n; i++){
  13.         cout << "Enter a number: ";
  14.         cin >> a[i];
  15.     }
  16.     for (int i=0; i < n; i++){
  17.         if (a[i]%2==0){even++;}
  18.     }
  19.      for (int i=0; i < n; i++){
  20.         if (a[i]%2==1){odd++;}
  21.     }
  22.     min = max = a[0];
  23.      for (int i=0; i < n; i++){
  24.         if (a[i]<min) {min=a[i];}
  25.     }
  26.     for (int i=0; i < n; i++){
  27.         if (a[i]>max) {max=a[i];}
  28.     }
  29.     for (int i=0; i < n; i++){
  30.         sum += a[i];
  31.     }
  32.     for (int i=0; i < n; i++){
  33.         product *= a[i];
  34.     }
  35.     avg =(double) sum/n;
  36.     for(int i=0; i<n; i++){
  37.         if (a[i]>avg) {moreavg++;}
  38.     }
  39.     for(int i = 0; i < n; i++) {
  40.         is_prime=true;
  41.     for(int j = 2; j < a[i]; j++) {
  42.         if(a[i]%j==0) {
  43.             is_prime = false;
  44.         }
  45.     }
  46.     if(is_prime==true) { prnumb++; }
  47.  
  48.     }
  49.     for(int i = 0; i < n; i++) {
  50.     num_cpy = a[i];
  51.     count = 0;
  52.     while(num_cpy!=0) {
  53.     count += (num_cpy%2);
  54.     num_cpy/=2;
  55.     }
  56.     if(count==1) { qdrnumb++; }
  57.  
  58.     }
  59.  
  60.  
  61.     cout << endl;
  62.     cout << "The sum of the numbers is: " << sum << endl;
  63.     cout << "The product of the numbers is: " << product << endl;
  64.     cout << "Min number: " << min << endl;
  65.     cout << "Max number: " << max << endl;
  66.     cout << "Even numbers: " << even << endl;
  67.     cout << "Odd numbers: " << odd << endl;
  68.     cout << "Average of the numbers: " << avg << endl;
  69.     cout << "Numbers bigger than the Average: " << moreavg << endl;
  70.     cout << "Prime numbers: " << prnumb << endl;
  71.     cout << "Quadratic numbers: " << qdrnumb << endl;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement