100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Introduction to algorithm exam

Rating
-
Sold
-
Pages
5
Uploaded on
10-02-2022
Written in
2021/2022

A real university exam for Introduction to algorithm using c++ language.

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
February 10, 2022
Number of pages
5
Written in
2021/2022
Type
Exam (elaborations)
Contains
Unknown

Subjects

Content preview

Question 1:
Using C++ programming language, write the following program:
(1) The program defines a constant SIZE equal to 20
(2) The program defines an array of integers with an array size equal to SIZE.
(3) The program reads 20 integers and store them in a array
(4) Without using any (swap) instruction, the program should reverse the positions of
values. The first value becomes the last one; the last value becomes the first one, and
so on, until the array becomes completely reversed.
Answer:


#include <iostream>

using namespace std;

const int SIZE=20;

void main(){

int A[SIZE];

int x;

for (int i=0; i< SIZE; i++)

{

cout << "Enter A[" << i <<"]: ";

cin >> A[i];

}

for (int i=0, j=SIZE-1; i<j; i++, j--)

{

x=A[i];

A[i]=A[j];

A[j]=x;

}

for (int i=0; i<SIZE; i++)

{

cout << A[i] << endl;

}

system("pause");

}

, Question 2:
Using C++ programming language, write the following program:
(1) The program should fix a constant SIZE equal to 20
(2) The program defines an array of integer with an array size equal to SIZE.
(3) The program reads 20 integers and store them in an array
(4) The program reads an integer value named (V).
(5) The program reads an array’s position named (index).
(6) The user should not be able to enter a value for index outside the scope of the
array.
(7) The program must put the value V at the position (index) in the array, shifting each
element from this position to the top, and dropping off the first element.


#include <iostream>

using namespace std;

const int SIZE=20;

void main(){

int A[SIZE];

int Value, index;

for (int i=0; i< SIZE; i++)

{

cout << "Enter A[" << i <<"]: ";

cin >> A[i];

}

cout << "Enter The Value V: ";

cin >> Value;

index=20;

while (index < 0 || index >= SIZE)

{

cout << "Enter The index: ";

cin >> index;

}

for (int i=SIZE-1; i>index; i--)

{
$5.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
abdulazizsnobrah

Get to know the seller

Seller avatar
abdulazizsnobrah AIU
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions