Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. https://www.onlinegdb.com/online_c_compiler
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6.  
  7. #include <stdlib.h>
  8.  
  9. #define MAX_LIN 3
  10.  
  11. #define MAX_COL 2
  12.  
  13. #define DIM_MAX 6
  14.  
  15. int main()
  16.  
  17. {
  18.  
  19.     int mat[10][10],i,j;
  20.  
  21.     int vec[DIM_MAX];
  22.  
  23.     int k = 0;
  24.  
  25.     printf("Enter your matrix\n");
  26.  
  27.     for(i=0;i<MAX_LIN;i++)
  28.  
  29.       for(j=0;j<MAX_COL;j++)
  30.  
  31.       {
  32.  
  33.         scanf("%d",&mat[i][j]);
  34.  
  35.       }
  36.  
  37.     printf("\nHere is your matrix:\n");
  38.  
  39.     //parcurgere matrice si verificare nr perfect
  40.  
  41.     for(i=0;i<MAX_LIN;i++)  
  42.  
  43.     {
  44.  
  45.         for(j=0;j<MAX_COL;j++)
  46.  
  47.         {
  48.  
  49.           if(CheckPerfectNumber(mat[i][j]) == 1)
  50.  
  51.           {
  52.  
  53.             vec[k] = mat[i][j];
  54.  
  55.             k++;
  56.  
  57.           }
  58.  
  59.         }
  60.  
  61.         printf("\n");
  62.  
  63.     }
  64.  
  65.     //printare vector
  66.  
  67.     for(i=0;i<k;i++)
  68.  
  69.         printf("%d ",vec[k]);
  70.  
  71. }
  72.  
  73.  
  74.  
  75. int CheckPerfectNumber(int number)
  76.  
  77. {
  78.  
  79.     int rem, sum = 0, i;
  80.  
  81.  
  82.     for (i = 1; i <= (number - 1); i++)
  83.  
  84.     {
  85.  
  86.         rem = number % i;
  87.  
  88.                 if (rem == 0)
  89.  
  90.         {
  91.  
  92.             sum = sum + i;
  93.  
  94.         }
  95.  
  96.     }
  97.  
  98.     if (sum == number)
  99.  
  100.     {
  101.  
  102.         printf("Entered Number is perfect number\n");
  103.  
  104.         return 1;
  105.  
  106.     }
  107.  
  108.     else
  109.  
  110.     {
  111.  
  112.         printf("Entered Number is not a perfect number\n");
  113.  
  114.         return 0;
  115.  
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement