ValerianBenchea

Nr. de cifre a numerelor prime dintr-un sir de n numere

Dec 4th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.    int n, d, i, x, nrdcf=0, c, p;
  8.    cout<<"n="; cin>>n;
  9.    for(i=1; i<=n; i++)
  10.    {
  11.        p=0;
  12.        cin>>x;
  13.        if(x==2)
  14.         {
  15.             nrdcf++;
  16.             p=1;
  17.         }
  18.  
  19.  
  20.        for(d=2; d<=x/2; d++)
  21.        {
  22.            if(x%d==0)
  23.             p++;
  24.        }
  25.        if(p==0)
  26.         {
  27.             while(x!=0)
  28.             {
  29.                 c=x%10;
  30.                 nrdcf++;
  31.                 x=x/10;
  32.             }
  33.         }
  34.    }
  35.  
  36.     cout<<nrdcf;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment