Advertisement
Guest User

ETE 1151 EXAM 2 - JONATHAN SYCIP

a guest
Apr 9th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. ETE 1151 - EXAM 2 - Jonathan Sycip - 04/09/2020
  2.  
  3. 1.
  4.     7    4    2    5    3    1
  5.  
  6. 2.
  7. using namespace std;
  8. #include <iostream>
  9. #include <stdlib.h>
  10.  
  11. void  xyz(int[], int); //print average of array elements
  12.  
  13. int main() {
  14.     int A[10] = { 1,2,3,4,5,6,7,8,9,10}; int n=10; //n refers to 10 elements.
  15.     xyz(A, n);
  16.     return 0;
  17. }
  18.  
  19. void xyz(int array[], int element) {
  20.     element = 10;
  21.     int total = 0, average = 0;
  22.     for (int i = 0; i < element; i++) {
  23.         total += array[i];
  24.     }
  25.     average = total / element;
  26.     cout << average;
  27. }
  28.  
  29. 3.
  30. using namespace std;
  31. #include <iostream>
  32. #include <stdlib.h>
  33.  
  34. int xyz(int, int, int);
  35.  
  36. int main() {
  37.     int apple, banana, strawberry;
  38.     cin >> apple;
  39.     cin >> banana;
  40.     cin >> strawberry;
  41.     cout << xyz(apple, banana, strawberry);
  42.     return 0;
  43. }
  44.  
  45. int xyz(int x, int y, int z) {
  46.     int a, b;
  47.     a = x + y + z;
  48.     b = a / 3;
  49.     return b;
  50. }
  51.  
  52. 4.
  53.    4   9  16  25
  54.  
  55. 5.
  56. a.
  57. double Area(double length, double width) {
  58.     double area;
  59.     area = length * width;
  60.     return area;
  61. }
  62. b.
  63. void array1(int arr[], int y) {
  64.  
  65. }
  66. c.
  67. int Product(int a, int b, int c) {
  68.     int product;
  69.     product = a * b * c;
  70.     return product;
  71. }
  72. d.
  73. double Volume(double s1, double s2, double s3) {
  74.     double volume;
  75.     volume = s1 * s2 * s3;
  76.     return volume;
  77. }
  78. 6.
  79. a.
  80. for (int i = 0; i < 10; i++) {
  81.     cin >> A[i];
  82. }
  83. b.
  84. for (int j = 0; j < 10;) {
  85.     sum += A[j];
  86.     j += 2;
  87. }
  88. c.
  89. for (int k = 10-1; k >= 0; k--) {
  90.     cout << A[k] << endl;
  91. }
  92. d.
  93. for (int l = 0; l < 10; l++) {
  94.     if (A[l] < 10) {
  95.         counter++;
  96.     }
  97. }
  98. cout << counter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement