Advertisement
0945928233

Đếm các giá trị là số nguyên tố trên đường chéo chính và đư

Jun 14th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5. int ngto(int n)
  6. {
  7. long int i,dem=0;;
  8. if(n==0||n==1) return 0;
  9. else
  10. {
  11. for(i=2;i<n;i++)
  12. {
  13. if(n%i==0) dem++;
  14. }
  15. if(dem>0) return 0;
  16. else return n;
  17. }
  18. }
  19. int main(int argc, char *argv[])
  20. {
  21. int n,i,j,A[100][100];
  22. scanf("%d",&n);
  23. for(i=0;i<n;i++)
  24. {
  25. for(j=0;j<n;j++)
  26. {
  27. scanf("%d",&A[i][j]);
  28. }
  29. }
  30. int dem=0,B[100],C[100];
  31. for(i=0;i<n;i++)
  32. {
  33. for(j=0;j<n;j++)
  34. {
  35. if((i+j==n-1&&A[i][j]!=0&&A[i][j]==ngto(A[i][j]))||(i==j&&A[i][j]!=0&&A[i][j]==ngto(A[i][j])))
  36. {
  37. B[dem]=A[i][j];
  38. dem++;
  39. }
  40. }
  41. }
  42. int dem2=0;
  43. for(i=0;i<dem;i++)//tao mot mang tuong tu A de xet phan tu da duoc duyet chua
  44. {
  45. C[i]=1;//b=1 la A[] chua duoc duyet
  46. }
  47. for(i=0;i<dem;i++)
  48. {
  49. int dem1=1;
  50. if(C[i])//xet den B[i]
  51. {
  52. C[i]=0;//A[] da duoc duyet
  53. for(j=i+1;j<dem;j++)
  54. {
  55. if(B[i]==B[j])
  56. {
  57. dem1++;
  58. C[j]=0;//B[j] da duoc duyet
  59. }
  60. }
  61. dem2++;
  62.  
  63. }
  64. }
  65. printf("%d",dem2);
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement