Docsity

exercises on c++ for prep engineer, Exercises of Computer Engineering and Programming

Partial preview of the text

Download exercises on c++ for prep engineer and more Exercises Computer Engineering and Programming in PDF only on Docsity!

Name : Mohamed Abdullah Mohamed Ali

ID : 20221393

Group : A1.

T.A : Eng. Dina ayman

ANSWER:

#include using namespace std; int main() { int arr[] = { 60 , 20 , 80 , 94 , 54 }; int size = sizeof(arr) / sizeof(arr[ 0 ]); cout << "the array elements is : "<<endl; for (int i = 0; i < size; i++) { cout << arr[i] << " " ; } cout << endl; return 0 ; }

Output 1 :

1. Displaying an array elements

Answer:

#include using namespace std; int main() { int arr[ 100000 ]; int n; cout << "HI! USER, WELCOME TO OUR PROGRAM:)"<<endl; cout << "How many number of elements do you want? "<<endl; cin >> n; for (int i = 0; i < n; i++) { cout << "Please,Enter element " << i + 1 << ": " ; cin >> arr[i]; } cout << "The elements of the array are: "; for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; return 0 ; }

3. Take inputs from user and store them in an array then display them

Output 1 :

Answer:

#include using namespace std; int main() { int arr[5] = { 88 , 96 , 52 , 44 , 69 }; int index = 3 ; cout << "The element at index " << index << " is: " << arr[index] << endl; return 0 ; }

OUTPUT 1 :

5. Create an array with size 5 and display element of index 3