Arrays: Namiq Sultan
Arrays: Namiq Sultan
Arrays
Namiq Sultan
University of Duhok
Department of Electrical and Computer Engineering
#include <iostream>
using namespace std;
int main()
{
short hours[6];
cout << "Enter the hours worked: ";
cin >> hours[0];
cin >> hours[1];
cin >> hours[2];
cin >> hours[3];
Holly
Warren
5 10 15 20 25 30 35 40
int main()
{
int collection[8] = {5, 10, 15, 20, 25, 30, 35, 40};
show(collection); // Passing address of array collection
}
5 10 15 20 25 30 35 40
5 10 15 20 25 30 35 40
2468
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
int set[Size] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
cout << "The arrays values are:\n";
for (int index = 0; index < Size; index++)
cout << set[index] << " ";
cout << endl;
doubleArray(set, Size);
cout << "After calling doubleArray, the values are:\n";
C++ Programming, Namiq Sultan 35
for (int index = 0; index < Size; index++)
cout << set[index] << " ";
cout << endl;
return 0;
}
HW:
• Count the repetition of number 0 in a given array.
• Find the sum of smallest and largest elements of a given array.
• Reverse the elements of a given array.
• C++ program to find the largest two numbers in a given array.
C++ Programming, Namiq Sultan 38
7.10 Two-dimensional Arrays
int main()
{
float sales[3][4]; // 2D array, 3 rows and 4 columns.
float totalSales = 0;// To hold the total sales.
int div, qtr; // Loop counters.
cout << "The total sales for the company are: $";
cout << totalSales << endl;
}
int main()
{
int Table[3][4] ={1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12};
float seat[3][5][8];