Advertisement
WadeRollins2710

[C++] [Array example]

Feb 6th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. //Array with procedure
  2. #include<iostream.h>
  3. #include<conio.h>
  4. int A[100], i, j, n, d , dem;
  5. void Nhap(void)
  6. {
  7.     clrscr( );
  8.     cout<<"Input the number of the elements: ";
  9.     cin>>n;
  10.     for (i=1;i<=n;i++)
  11.     {
  12.         cout<<"Input the element number "<<i<<": ";
  13.         cin>>A[i];
  14.     }
  15.     clrscr( );
  16.     for (i=1;i<=n;i++)
  17.         cout<<A[i]<<" ";
  18.     cout<<endl;
  19. }
  20. int Nt(int m)
  21. {
  22.     int dem=0, j;
  23.     for (j=1;j<=m;j++)
  24.         if (m%j==0) dem++;
  25.     if (dem==2) return 1;
  26.         else return 0;
  27. }
  28. int Cp(int m)
  29. {
  30.     int j;
  31.     for (j=1;j<=m;j++)
  32.         if (j*j==m) return 1;
  33. }
  34. int Hh(int m)
  35. {
  36.     int j, S=0;
  37.     for (j=1;j<m;j++)
  38.         if (m%j==0) S=S+j;
  39.     if (S==m) return 1;
  40.        else return 0;
  41. }
  42.  
  43. void Find_Number(void)
  44. {
  45.     dem=0;
  46.     cout<<"Prime number: ";
  47.     for (i=1;i<=n;i++)
  48.         if (Nt(A[i])==1)
  49.         {
  50.             dem++;
  51.             cout<<A[i]<<" ";
  52.         }
  53.     if (dem==0) cout<<"None!";
  54.     cout<<endl;
  55.     dem=0;
  56.     cout<<"Square number: ";
  57.     for (i=1;i<=n;i++)
  58.         if (Cp(A[i])==1)
  59.         {
  60.             dem++;
  61.             cout<<A[i]<<" ";
  62.         }
  63.     if (dem==0) cout<<"None!";
  64.     cout<<endl;
  65.     dem=0;
  66.     cout<<"Perfect number: ";
  67.     for (i=1;i<=n;i++)
  68.         if (Hh(A[i])==1)
  69.         {
  70.             dem++;
  71.             cout<<A[i]<<" ";
  72.         }
  73.     if (dem==0) cout<<"None!";
  74.     cout<<endl;
  75. }
  76. main( )
  77. {
  78.     Nhap( );
  79.     Find_Number( );
  80.     getch( );
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement