fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define max 100
  4. int negative(int a[], int n)
  5. {
  6. // display menu
  7. printf("\n1. Input N and array of integer numbers");
  8. printf("\n2.Find the largest even negative");
  9. printf("\n3.Calculate total of the ODD numbers");
  10. printf("\n4.Calculate greatest common divisor of all array members");
  11. printf("\n5.Display all elements");
  12. printf("\n6.Exit");
  13. int max_negative = -1e9, dem = 0;
  14. int i;
  15. for (i = 0; i < n; i++)
  16. {
  17. if (a[i] < 0 && a[i] > max_negative && a[i] % 2 == 0)
  18. {
  19. max_negative = a[i];
  20. dem++;
  21. }
  22. if (!dem)
  23. {
  24. return 0;
  25. return max_negative;
  26. }
  27. }
  28. }
  29. int sum(int a[], int n)
  30. {
  31. int res = 0;
  32. int i;
  33. for (i = 0; i < n; i++)
  34. {
  35. if (a[i] % 2 != 0)
  36. {
  37. res += a[i];
  38. }
  39. }
  40. return res;
  41. }
  42. int gcd(int a, int b)
  43. {
  44. if (b == 0)
  45. return a;
  46. return gcd(b, a % b);
  47. }
  48. int gcd_array(int a[], int n)
  49. {
  50. int res = a[0];
  51. int i;
  52. for (i = 1; i < n; i++)
  53. res = gcd(res, a[i]);
  54. return res;
  55. }
  56. void sort(int a[], int n)
  57. {
  58. int i, j;
  59. for (i = 0; i < n - 1; i++)
  60. {
  61. for (j = 0; j < n - i - 1; j++)
  62. {
  63. if (a[j] > a[j + 1])
  64. {
  65. int tmp = a[j];
  66. a[j] = a[j + 1];
  67. a[j + 1] = tmp;
  68. }
  69. }
  70. }
  71. }
  72. int main()
  73. {
  74. int n;
  75. scanf("%d", &n);
  76. printf("N=%d\n", n);
  77. int a[n];
  78. int i;
  79. for (i = 0; i < n; i++)
  80. scanf("%d", &a[i]);
  81. printf("%d\n", negative(a, n));
  82. printf("%d\n", sum(a, n));
  83. printf("%d\n", gcd_array(a, n));
  84. sort(a, n);
  85. for (i = 0; i < n; i++)
  86. printf("%d ", a[i]);
  87. }
  88.  
Success #stdin #stdout 0s 5536KB
stdin
Standard input is empty
stdout
N=0

1. Input N and array of integer numbers
2.Find the largest even negative
3.Calculate total of the ODD numbers
4.Calculate greatest common divisor of all array members
5.Display all elements
6.Exit0
0
0