Write a program that asks the user to enter 10 integers stored in an array. The program must display the number of integers greater than or equal to 10.
The purpose of this exercise is to check the following technical points:
Simple use of arrays.
A simple algorithm on an array: Finding the number of elements checking a property.
Here is the source file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <iostream> using namespace std; const int N = 10; int main () { int t [10], i, nb = 0; for (i = 0; i <N; i ++) {cout << "Type an integer"; cin >> t [i];} for (i = 0; i <N; i ++) if (t [i]> = 10) nb ++; cout << "The number of integers equal to 10 or more is:" Nb << << endl; return 0; } |
Write a program that asks the user to enter 10 integers stored in a table as well as an integer V. The program must find if V is in the array and show “V is in the array” or “V is not not found in the array “.
The purpose of this exercise is to check the following technical points:
Simple use of arrays.
A simple algorithm on an array: Search for an element in an array.
Here is the source file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> using namespace std; const int N = 10; int main () { int t [N], i, V; bool finds; for (i = 0; i <N; i ++) {cout << "Type an integer"; cin >> t [i];} cout << "Enter the value of V:"; cin >> V; found = false; i = 0; while (! finds && i <N) if (t [i] == V) is = true; else i ++; if (found) cout << "The value V is in the array" << endl; else cout << "The value V is not in the array" << endl; return 0; } |
Write a program that asks the user to enter 10 integers stored in an array. The program must then display the index of the largest element.
The purpose of this exercise is to check the following technical points:
Simple use of arrays.
A simple algorithm on an array: search for the index of the largest element.
Here is the source file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> using namespace std; const int N = 10; int main () { int t [N], i, index; for (i = 0; i <N; i ++) {cout << "Type an integer"; cin >> t [i];} index = 0; for (i = 1; i <N; i ++) if (t [index] <t [i]) i = index; cost << "The index of the largest element is:" << index << endl; return 0; } |
Write a program that asks the user to enter 10 integers stored in an array and an integer V. The program must find if V is in the array and must delete the first occurrence of V by shifting one box to the left the following items and adding a 0 at the end of the array . The program must then display the final array .
The purpose of this exercise is to check the following technical points:
Simple use of arrays.
A simple algorithm on an array: deletion of an element with offset of the following.
Here is the source file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> using namespace std; const int N = 10; int main () { int t [N], i, j, V; bool finds; for (i = 0; i <N; i ++) {cout << "Type an integer"; cin >> t [i];} cout << "Enter the value of V:"; cin >> V; found = false; i = 0; while (! finds && i <N) if (t [i] == V) is = true; else i ++; if (found) { for (j = i; j <N-1; j ++) t [j] = t [j + 1]; t [N-1] = 0; } for (i = 0; i <N; i ++) cout << t [i] << endl; return 0; } } |