Group Members Hashim Hammoud Al-Mansouri Taher Subait Rayhan Abdulqader Khalid Mosaqa Mahmoud Ahmed Kasour Abdulrahman Faraj Jubah
Group Members Hashim Hammoud Al-Mansouri Taher Subait Rayhan Abdulqader Khalid Mosaqa Mahmoud Ahmed Kasour Abdulrahman Faraj Jubah
Homework :
Given three arrays a, b and c, write a program to compare first element of array a with
first element of array b, then put the result on array c and so on. Then, if array c
elements is even print it, if not print the next even number of this element.
a) If a[ i ] is greater than b[ i ]
Do c[ i ] = a[ i ]
b) Else,
Do c[ i ] = b[ i ]
b) Else, print c[ i ] + 1
5) End.
Code of Implementation :
1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. int a[5] = { 1, 2, 7, 4, 8 };
6. int b[5] = { 3, 4, 3, 6, 5 };
7. int c[5];
8.
9. for ( int i = 0 ; i < 5 ; i++ )
10. {
11. if ( a[i] > b[i] )
12. c[i] = a[i];
13.
14. else
15. c[i] = b[i];
16. }
17.
18. for ( int i = 0 ; i < 5 ; i++ )
19. {
20. if ( c[i] % 2 == 0 )
21. cout << c[i] << " ";
22.
23. else
24. cout << c[i]+1 << " ";
25. }
26.
27. system("pause");
28. return 0;
29. }