0% found this document useful (0 votes)
39 views5 pages

20BCS7127 CC 1.1

Student Bhupen Garg conducted an experiment on competitive coding. The experiment involved two problems - printing an array in reverse order and finding the sum of elements in an array. For the first problem, the student took input of array size and elements, stored them in an array, and printed the elements in reverse order. For the second problem, the student took input of array size and elements, initialized a sum variable, iterated through the array adding elements to sum, and printed the final sum. The student solved both problems using C++.

Uploaded by

Bhupen Garg
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)
39 views5 pages

20BCS7127 CC 1.1

Student Bhupen Garg conducted an experiment on competitive coding. The experiment involved two problems - printing an array in reverse order and finding the sum of elements in an array. For the first problem, the student took input of array size and elements, stored them in an array, and printed the elements in reverse order. For the second problem, the student took input of array size and elements, initialized a sum variable, iterated through the array adding elements to sum, and printed the final sum. The student solved both problems using C++.

Uploaded by

Bhupen Garg
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/ 5

Experiment 1.

1
Student Name: Bhupen Garg UID: 20BCS7127
Branch: CSE Section/Group: 902/B(MM)
Semester: 5th Date of Performance: 28-08-2022
Subject Name: Competitive Coding Subject Code: 20CSP-314

Problem Statement 1:
Objective:
Today, we will learn about the Array data structure. Check out the Tutorial tab for learning
materials and an instructional video.
Task
Given an array, A, of N integers, print A's elements in reverse order as a single line of space-
separated numbers.
Example
A = [1,2,3,4]
Print 4 3 2 1. Each integer is separated by one space.
Input Format
The first line contains an integer, N (the size of our array).
The second line contains N space-separated integers that describe array A's elements.

Code:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
Competitive Coding Lab Subject Code: 20CSP-314
cin>>n;
int arr[n];
for(int i = 0; i<n; i++){
cin>>arr[i];
}
// cout<<"\n\n20BCS7127\n\n"<<endl;
for(int i = n-1; i>=0; i--){
cout<<arr[i]<<" ";
}
return 0;
}
Output:

Competitive Coding Lab Subject Code: 20CSP-314


Problem Statement 2:

Objective:
Given an array of integers, find the sum of its elements.
For example, if the array , ar = [1,2,3], 1 + 2 + 3 = 6 , so return 6.

Function Description:

Complete the simpleArraySum function in the editor below. It must return the sum of the array
elements as an integer.

simpleArraySum has the following parameter(s):

ar: an array of integers

Input Format:

The first line contains an integer, n, denoting the size of the array.
The second line contains n space-separated integers representing the array's elements.Given an
array of integers, find the sum of its elements.
Code:
#include<bits/stdc++.h>
Competitive Coding Lab Subject Code: 20CSP-314
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0; i<n; i++) {
cin>>arr[i];
}
int sum = 0;

for (int i=0; i<n; i++) {


sum += arr[i];
}
// cout<<"\n\n20BCS7127\n\n"<<endl;
cout<<sum;
return 0;
}
Output:

Competitive Coding Lab Subject Code: 20CSP-314


Competitive Coding Lab Subject Code: 20CSP-314

You might also like