0% found this document useful (0 votes)
14 views3 pages

Computer Science & Engineering: Department of

Uploaded by

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

Computer Science & Engineering: Department of

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment :- 1

Student Name: Vanshika UID: 22BET10032


Branch: BE-IT Section/Group: 22BET_IOT_701/A
th
Semester: 5 Date of Performance: 17-07-24
Subject Name: Advanced Programming Lab - 1
Subject Code: 22ITP-314

1. Aim:

Given an array, of size, reverse it. Example: If array, arr = {1,2,3,4,5}, after reversing it, the array
should be, arr = {5,4,3,2,1}.

2. Objective:
● To learn about Array Data Structure.
● To learn different approaches to reverse the elements in Array.

3. Implementation/Code:

#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
for(int i = n - 1; i >= 0; i--) {
printf("%d ", arr[i]);
}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Output

5. Time Complexity :

Input Reading: Reading nnn elements into the array takes O(n) time.

Array Reversal: Reversing the array using a loop from n−1 to 0 also takes O(n) time.

Output: Printing the reversed array elements takes O(n) time.

Overall Time Complexity: The entire program operates in O(n) time complexity due to the
O(n) operations involved in input reading, array reversal, and outputting the results.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

6. Learning Outcomes:
• learn the concept of in-place modification, where the array itself is modified without
requiring additional memory space.
• Understand the time complexity of the array reversal algorithm.
• program encourages algorithmic thinking by presenting a problem (array reversal) and
guiding learners through the steps required to solve it.
• gain a deeper understanding of how array indices work and how pointers can be used
effectively to manipulate array elements.
• Demonstrates the importance of verifying program output to ensure correctness, in this
case, by printing both the original and reversed arrays.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy