0% found this document useful (0 votes)
7 views6 pages

Computer Science & Engineering: Department of

Uploaded by

veer371karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Computer Science & Engineering: Department of

Uploaded by

veer371karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment1.1

Student Name: Anuj Anand UID: 22BCS80050


Branch: BE CSE Section/Group: IOT-607-B
Semester: 5th Date of Performance: 4/08/23
Subject Name: Advanced Programming Subject Code: 21CSP-314

Aim:
1 - Given an array, A , of N integers, print A's elements in reverse order as a
single line of space-separated numbers.
2 - Given an array of integers, find the sum of its elements.
Objective: To implement the concept of Dynamic Array

1-
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2-
Pseudo code :
1- function main():
integer a
read a
integer numbers[a]
for i from 0 to a - 1:
read numbers[i]
for n from a - 1 to 0 step -1:
print numbers[n] followed by " "
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

return 0
2 - function simpleArraySum(ar):
integer sum = 0
for i from 0 to length of ar - 1:
sum = sum + ar[i]
return sum
function main():
integer n
read n
vector of integers ar with size n
for i from 0 to n - 1:
read ar[i]
integer result = simpleArraySum(ar)
print result
return 0
Program code :
1 –#include <iostream>

using namespace std;

int main() {

int a;
cin>>a;
int numbers[a];
for (int i = 0; i < a; i++) {
cin >> numbers[i]; }
for (int n = a-1; n >= 0; --n)
{
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

cout << numbers[n] << " ";


}
return 0;
}
2- #include <iostream>

#include <vector>
using namespace std;

int simpleArraySum(vector<int> ar) {


int sum = 0;
for (int i = 0; i < ar.size(); ++i) {
sum += ar[i];
}
return sum;
}
int main() {
int n;
cin >> n;
vector<int> ar(n);
for (int i = 0; i < n; ++i) {
cin >> ar[i];
}
int result = simpleArraySum(ar);
cout << result << endl;
return 0;
}

Output :
1-
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2–
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like