返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. bool compute(int a)
  4. {
  5.     for(int i=2 ; i<=sqrt(a) ; i++)
  6.     {
  7.         if(a%i == 0)
  8.         {
  9.             return 0;
  10.         }
  11.     }
  12.     return 1;
  13. }
  14. int main()
  15. {
  16.     int n;
  17.     cin >> n;
  18.     if(compute(n))
  19.         cout << n << " is a prime number";
  20.     else
  21.         cout << n << " is not a prime number";
  22.    
  23.     return 0;
  24. }
複製代碼
Vincent

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n , sum[7]={0};
  4. int main()
  5. {
  6.     for(int i=1 ; i<=10 ; i++)
  7.     {
  8.         cin >> n;
  9.         if(n>=1 && n<=6)
  10.             sum[n]++;
  11.         else
  12.             sum[0]++;
  13.     }

  14.     for(int i=1 ; i<=6 ; i++)
  15.         cout << "number" << i << ":" << sum[i] << endl;
  16.     cout << "error:" << sum[0] << endl;
  17.     return 0;
  18. }
複製代碼
Vincent

TOP

返回列表