REVISION 9 Arrays and Functions
REVISION 9 Arrays and Functions
int sum = 0;
for( int i = 0; i < 4; i++ )
sum += A [ i ] * B [ i ];
(2)- Show the initial and final contents of the array “A”
int n= 8, j = 1; A A
After After
A B
#include <iostream>
using namespace std;
void main()
{
int A[7] = {66, 55, 77, 55, 88, 77, 66};
int B[7];
int num = 55;
int k = 0;
=================================================================================================================
(4)- Create a program segment that takes a 1-D array and flips all its variables. Example
below:
14 12
67 98
3 73
31 74
38 38
74 31
73 3
98 67
12 14
==========================================================
(5)- Write a C++ program that find the common elements between two
arrays of variable sizes. Your program should ask the user to input the sizes
of the two arrays and the elements in each of them. The program then
should display the common elements that appear in both arrays.
Sample Input:
4 7 11 3 9
8 1 4 12 10 7 2
Output:
4
7
================================================================
(6)- Write only the C++ code to create the following array and and fill it with the shown
data. Also, the the code to display the array content as a 2D array.
A X X X X
X A X X X
X X A X X
X X X A X
X X X X A
(7)- Write only the C++ code to create the following array and and fill it with the shown data. Also,
the the code to display the array content as a 2D array.
A X X X X
A A X X X
A A A X X
A A A A X
A A A A A
====================================================================
int main ()
{
int n=0;
}
n++;
cout<< endl
}
=============================================================
b-
int main ()
{
int n=1 , j=1;
#include <iostream.h>
int main ()
{
int i=1;
cout<< endl
}
}
=====================================================
Arrays :
1. Write a C++ function that finds the second largest element in an array of
doubles.
=======================================================