fork download
  1. #include <stdio.h>
  2. #define MAX 100
  3.  
  4. int isPrime(int n) {
  5. if(n < 2) return 0;
  6. for(int i = 2; i <= n/2; i++)
  7. if(n % i == 0) return 0;
  8. return 1;
  9. }
  10.  
  11. int main() {
  12. int n, choice;
  13. float a[MAX];
  14.  
  15. printf("Enter n: ");
  16. scanf("%d", &n);
  17.  
  18. printf("Enter array:\n");
  19. for(int i = 0; i < n; i++) {
  20. scanf("%f", &a[i]);
  21. }
  22.  
  23. do {
  24. printf("\n----- MENU -----\n");
  25. printf("1. Input array\n");
  26. printf("2. Print array\n");
  27. printf("3. Average\n");
  28. printf("4. Sum positive\n");
  29. printf("5. Reverse array\n");
  30. printf("6. Check symmetric\n");
  31. printf("7. Check increasing\n");
  32. printf("8. Max even\n");
  33. printf("9. Delete value x\n");
  34. printf("0. Exit\n");
  35.  
  36. printf("Choose: ");
  37. scanf("%d", &choice);
  38.  
  39. if(choice == 1) {
  40. printf("Re-enter array:\n");
  41. for(int i = 0; i < n; i++) {
  42. scanf("%f", &a[i]);
  43. }
  44. }
  45.  
  46. else if(choice == 2) {
  47. for(int i = 0; i < n; i++)
  48. printf("%.2f ", a[i]);
  49. printf("\n");
  50. }
  51.  
  52. else if(choice == 3) {
  53. float sum = 0;
  54. for(int i = 0; i < n; i++) sum += a[i];
  55. printf("Average = %.2f\n", sum/n);
  56. }
  57.  
  58. else if(choice == 4) {
  59. float sum = 0;
  60. for(int i = 0; i < n; i++)
  61. if(a[i] > 0) sum += a[i];
  62. printf("Sum positive = %.2f\n", sum);
  63. }
  64.  
  65. else if(choice == 5) {
  66. for(int i = 0; i < n/2; i++) {
  67. float t = a[i];
  68. a[i] = a[n-1-i];
  69. a[n-1-i] = t;
  70. }
  71. printf("Reversed!\n");
  72. }
  73.  
  74. else if(choice == 6) {
  75. int ok = 1;
  76. for(int i = 0; i < n/2; i++)
  77. if(a[i] != a[n-1-i]) ok = 0;
  78.  
  79. if(ok) printf("Symmetric\n");
  80. else printf("Not symmetric\n");
  81. }
  82.  
  83. else if(choice == 7) {
  84. int ok = 1;
  85. for(int i = 1; i < n; i++)
  86. if(a[i] < a[i-1]) ok = 0;
  87.  
  88. if(ok) printf("Increasing\n");
  89. else printf("Not increasing\n");
  90. }
  91.  
  92. else if(choice == 8) {
  93. int found = 0;
  94. int max = -1;
  95.  
  96. for(int i = 0; i < n; i++) {
  97. if((int)a[i] % 2 == 0) {
  98. if(!found || a[i] > max) {
  99. max = (int)a[i];
  100. found = 1;
  101. }
  102. }
  103. }
  104.  
  105. if(found) printf("Max even = %d\n", max);
  106. else printf("No even number\n");
  107. }
  108.  
  109. else if(choice == 9) {
  110. float x;
  111. printf("Enter x: ");
  112. scanf("%f", &x);
  113.  
  114. int k = 0;
  115. for(int i = 0; i < n; i++) {
  116. if(a[i] != x) {
  117. a[k++] = a[i];
  118. }
  119. }
  120. n = k;
  121. printf("Deleted!\n");
  122. }
  123.  
  124. } while(choice != 0);
  125.  
  126. return 0;
  127. }
Success #stdin #stdout 0s 5304KB
stdin
5
1 2 3 4 5
2
0
stdout
Enter n: Enter array:

----- MENU -----
1. Input array
2. Print array
3. Average
4. Sum positive
5. Reverse array
6. Check symmetric
7. Check increasing
8. Max even
9. Delete value x
0. Exit
Choose: 1.00 2.00 3.00 4.00 5.00 

----- MENU -----
1. Input array
2. Print array
3. Average
4. Sum positive
5. Reverse array
6. Check symmetric
7. Check increasing
8. Max even
9. Delete value x
0. Exit
Choose: