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

Manipal University

The document outlines a programming assignment for students at Manipal University, specifically focusing on creating a bank account management system and swapping elements in an array using pointers. It includes problem statements, input and output formats, sample test cases, and example code in C. The assignment is part of the NeoColab DSA Lab Course for the CSE department, with specific details about the student's performance and contact information.

Uploaded by

aaravtyagi00016
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)
51 views5 pages

Manipal University

The document outlines a programming assignment for students at Manipal University, specifically focusing on creating a bank account management system and swapping elements in an array using pointers. It includes problem statements, input and output formats, sample test cases, and example code in C. The assignment is part of the NeoColab DSA Lab Course for the CSE department, with specific details about the student's performance and contact information.

Uploaded by

aaravtyagi00016
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

45

Manipal University

45

45
04
00

00

00
50
05

05

05
0
02

02

02

02
Name: Aarav Tyagi Scan to verify results
25

25

25

25
Email: aarav.2502050045@[Link]
Roll no: 2502050045
Phone: 9759977500
Branch: Manipal
Department: CSE - H1
Batch: 2029
Degree: [Link]
5

45

45

45
04

00

00
50

50

NeoColab_Manipal_2029_DSA Lab Course

05

05
20

20

02

02
0

0
25

25

25

25
Neocolab_Manipal_DSA_Week 2_PAH

Attempt : 1
Total Mark : 20
Marks Obtained : 20

Section 1 : Coding

1. Problem Statement
45

45

45

45
0

00

00

00
50

Gokul wants to create a simple bank account management system. He


05

05

05
0
02

02

02

wants to be able to deposit and withdraw money from his account and 02
25

25

25

25
check his account balance.

You need to help him implement this system using pointer arithmetic.

Input Format
The input consists of a series of inputs from the user in the following format:

An integer choice (1, 2, 3, or 4) represents the user's menu selection.


45

45

45

45

1. Deposit
00

00

00

00

2. Withdraw
05

05

05

05

3. Display Balance
02

02

02

02
25

25

25

25
4. Exit
45

45

45
04
00

00

00
50
05

05

05
If the choice is 1 (Deposit) or 2 (Withdraw), the choice is followed by an integer

0
02

02

02

02
representing the amount to deposit or withdraw, separated by a space.
25

25

25

25
Note: Option 4 is mandatory to terminate the program.
Output Format
The output displays the following information in separate lines:

1. For deposit and withdrawal operations, print "Deposit successful." or


5

45

45

45
04

00

00
"Withdrawal successful." as appropriate.
50

50

05

05
20

20

2. If the user attempts to withdraw more money than the account balance, print

02

02
0

"Insufficient balance."
25

25

25

25
3. When checking the account balance, print "Current Balance: " followed by the
account balance (an integer).
4. For invalid choices, print "Invalid choice."
5. After choosing to exit the program, print "Exiting program."

Refer to the sample outputs for a better understanding.


45

45

45

45
Sample Test Case
0

00

00

00
50

05

05

05
0

Input: 1 100
02

02

02

2 300
02
25

25

25

25

3
4
Output: Deposit successful.
Insufficient balance.
Current Balance: 100
Exiting program.
Answer
// You are using GCC
45

45

45

45

#include<stdio.h>
00

00

00

00

int main() {
05

05

05

05

int choice;
02

02

02

02
25

25

25

25
int amount;
45

45

45
04
00

00

00
int balance=0;

50
05

05

05
int *ptr=&balance;

0
02

02

02

02
25

25

25

25
while(1) {
scanf("%d", &choice);

if(choice == 1){
scanf("%d",&amount);
*ptr += amount;
printf("Deposit successful.\n");
}
else if (choice==2){
scanf("%d",&amount);
5

45

45

45
04

00

00
if(*ptr>=amount){
50

50

05

05
*ptr-=amount;
20

20

02

02
0

printf("Withdrawal successful.\n");
25

25

25

25
}
else{
printf("Insufficient balance.\n");
}
}
else if (choice==3){
printf("Current balance:%d\n",*ptr);
}
else if (choice==4){
printf("Exiting program.");
45

45

45

45
0

00

00

00
break;
50

05

05

05
}else{
0
02

02

02

printf("Invalid choice.\n"); 02
25

25

25

25

}
}
return 0;}

Status : Correct Marks : 10/10

2. Problem Statement
45

45

45

45

John wants to write a program to understand how to swap the first and
00

00

00

00

last elements of an integer array using pointers. Help him by writing a C


05

05

05

05

program that takes the number of elements in the array and the array
02

02

02

02
25

25

25

25
elements as input from the user.
45

45

45
04
00

00

00
50
05

05

05
0
Your program should then swap the first and last elements of the array
02

02

02

02
using pointers and display the array before and after the swap.
25

25

25

25
Input Format
The first line consists of an integer n, representing the number of elements of an
array.

The second line consists of n space-separated elements representing the


elements of the array.
Output Format
5

45

45

45
04

00

00
The first line prints "Array before swap: " followed by the array before swapping
50

50

05

05
separated by a space.
20

20

02

02
0

0
25

25

25

25
The second line prints "Array after swap: " followed by the array after swapping
separated by a space.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 4
45

45

45

45
0

00

00

00
5192
50

05

05

05
0

Output: Array before swap: 5 1 9 2


02

02

02

02
25

25

25

25
Array after swap: 2 1 9 5
Answer
// You are using GCC
#include<stdio.h>
int main(){
int n;
int arr[20];
int *p;
int temp;
45

45

45

45

scanf("%d",&n);
00

00

00

00

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

05

05

05

scanf("%d",&arr[i]);
02

02

02

02
25

25

25

25
}
45

45

45
04
00

00

00
printf("Array before swap: ");

50
05

05

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

0
02

02

02

02
printf("%d",arr[i]);
25

25

25

25
}
printf("\n");
p=arr;
temp=*p;
*p=*(p+n-1);
*(p+n-1)=temp;
printf("Array after swap:");
for(int i=0;i<n;i++){
printf("%d",arr[i]);
}
5

45

45

45
04

00

00
return 0;
50

50

05

05
}
20

20

02

02
0

0
25

25

25

25
Status : Correct Marks : 10/10
45

45

45

45
0

00

00

00
50

05

05

05
0
02

02

02

02
25

25

25

25
45

45

45

45
00

00

00

00
05

05

05

05
02

02

02

02
25

25

25

25

You might also like