Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 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

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--)

{

Written for

Course

Document information

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

Subjects

$5.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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
-
Member since
4 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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions