Advertisement
vallec

Untitled

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