Advertisement
vallec

Untitled

Dec 11th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6. printf("Da se sustavi programa za obrabotka na dvumerniq masiv A[N, N], kudeto dannite sa celi chisla v intervala [-10, 10]\n");
  7. printf("Da se obrazuva ednomeren masiv C, elementite na koito sa elementite ot masiva A, chiito kvadrati sa po - golemi ot 50\n");
  8. printf("Polucheniqt masiv da se sortira po golemina\n");
  9. printf("Avtor: Violeta Starcheva\n");
  10.  
  11.  
  12. int n;
  13.  
  14. printf("Enter size of the array: ");
  15. scanf("%d", &n);
  16. int A[n][n];
  17.  
  18. for(int i = 0; i < n; i++){
  19. for(int j = 0; j < n; j++){
  20. printf("A[%d][%d] = ", i, j);
  21. scanf("%d", &A[i][j]);
  22. }
  23. }
  24.  
  25. printf("---------------\n");
  26.  
  27. for(int i = 0; i < n; i++){
  28. for(int j = 0; j < n; j++){
  29. printf("A[%d][%d] = %d\n", i, j, A[i][j]);
  30. }
  31. }
  32.  
  33. int foundElements = 0;
  34.  
  35.  
  36. for(int i = 0; i < n; i++){
  37. for(int j = 0; j < n; j++){
  38. if(pow(A[i][j], 2) > 50){
  39. foundElements++;
  40. }
  41. }
  42. }
  43.  
  44. int C[foundElements];
  45. int index = 0;
  46. for(int i = 0; i < n; i++){
  47. for(int j = 0; j < n; j++){
  48. if(pow(A[i][j], 2) > 50){
  49. C[index] = A[i][j];
  50. index++;
  51. }
  52. }
  53. }
  54.  
  55. int a;
  56.  
  57. for (int i = 0; i < foundElements; ++i)
  58. {
  59. for (int j = i + 1; j < foundElements; ++j)
  60. {
  61. if (C[i] < C[j])
  62. {
  63. a = C[i];
  64. C[i] = C[j];
  65. C[j] = a;
  66. }
  67. }
  68. }
  69.  
  70. printf("Result:\n");
  71.  
  72. for (int i = 0; i < foundElements; ++i)
  73. {
  74. printf("%d\n", C[i]);
  75. }
  76.  
  77.  
  78.  
  79. return 0;
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement