Advertisement
Guest User

Laba8(B) 17

a guest
Feb 24th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #define M 5
  6. #define N 7
  7. #define A -50
  8. #define B 50
  9.  
  10. void Init(int a[][N],int m , int n)
  11. {
  12. int i,j;
  13. for(i = 0 ; i < m ; i++)
  14. for(j = 0 ; j < n ; j++)
  15. a[i][j]=A+rand()%(B-A+1);
  16. }
  17. void Print(int a[][N],int m,int n)
  18. {
  19. int i,j;
  20. for(i = 0 ; i < m; i++)
  21. {
  22. for(j = 0 ; j < n ; j++)
  23. printf("%4d",a[i][j]);
  24. printf("\n");
  25. }
  26. printf("\n");
  27. }
  28. int Prostoe(int a)
  29. {
  30. a=abs(a);
  31.  
  32. if (a==2)
  33. return 1;
  34. if (a==0 || a==1 || a%2==0)
  35. return 0;
  36. int i=3;
  37. while(i <= a/2 && a%i != 0)
  38. i+=2;
  39. return i>a/2;
  40. }
  41. int CountStr(int a[][N],int m,int n)
  42. {
  43. int i,j,count=0,flag=0,max=0,buf=0;
  44. for( i = 0 ; i < m; i++)
  45. {
  46. for(j = 0 ; j < n ; j++)
  47. if(Prostoe(a[i][j])==1)
  48. {
  49. printf("==%4d",a[i][j]);
  50. count++;
  51. flag=1;
  52. }
  53. if(count>=max)
  54. {
  55. max=count;
  56. buf=i;
  57. }
  58. count=0;
  59. }
  60. if (flag==0)
  61. return -1;
  62. if (flag)
  63. return buf;
  64. }
  65. int main()
  66. {
  67. int a[M][N],b[M],buf;
  68. srand(time(NULL));;
  69. Init(a,M,N);
  70. Print(a,M,N);
  71. buf=CountStr(a,M,N);
  72. if(buf==-1)
  73. printf("Net Stroki s prostimi 4islami");
  74. else
  75. printf("\nNomer Stroki=%d\n",buf);
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement