0% found this document useful (0 votes)
49 views2 pages

Group Members Hashim Hammoud Al-Mansouri Taher Subait Rayhan Abdulqader Khalid Mosaqa Mahmoud Ahmed Kasour Abdulrahman Faraj Jubah

The document describes a homework assignment to write a program that compares the first elements of three arrays (a, b, c) and stores the results in array c. It then prints the elements of c, or the next even number if the element is odd. It provides the algorithm, description, and C++ code to implement the solution, looping through the arrays to compare elements and store results in c, then loop through c to print elements or their next even values.

Uploaded by

polat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Group Members Hashim Hammoud Al-Mansouri Taher Subait Rayhan Abdulqader Khalid Mosaqa Mahmoud Ahmed Kasour Abdulrahman Faraj Jubah

The document describes a homework assignment to write a program that compares the first elements of three arrays (a, b, c) and stores the results in array c. It then prints the elements of c, or the next even number if the element is odd. It provides the algorithm, description, and C++ code to implement the solution, looping through the arrays to compare elements and store results in c, then loop through c to print elements or their next even values.

Uploaded by

polat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

Algorithm and Description :

1) Define three arrays a, b and c.

2) Define the elements of a and b arrays.

3) For i = 0 until i < n , Do the following :

a) If a[ i ] is greater than b[ i ]

Do c[ i ] = a[ i ]

b) Else,

Do c[ i ] = b[ i ]

4) For i = 0 until i < n , Do the following :

a) If c[ i ] is even, print it.

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. }

You might also like