VISVESVARAYA TECHNOLOGICAL
UNIVERSITY
Jnana Sangama, Belagavi - 590 014.
B.L.D.E ASSOCIATION’S
VACHANA PITAMAHA Dr. P. G. HALKATTI COLLEGE OF
ENGINEERING AND
TECHNOLOGY, VIJAYAPURA – 586103
DEPARTMENT OF COMPUTER
SCIENCE AND ENGINEERING (D.S)
Principals of Programming using C (BPOP203)
ASSIGNMENT REPORT ON
“Switch and Functions”
SUBMITTED BY
Name : SHREYANK HIREMATH
Roll No: 527
Division : I
USN:2BL23CD058
Course Coordinator
Prof. Gayatri Bajantri
C PROGRAM MENU OF ATM :
#include <stdio.h>
#include <string.h>
int main() {
// Define username and password
char username[] = "shreyank";
char password[] = "pass1234";
// Variables to store user input
char input_username[20];
char input_password[20];
// Authentication loop
while (1) {
printf("Enter username: ");
scanf("%s", input_username);
printf("Enter password: ");
scanf("%s", input_password);
// Check if username and password match
if (strcmp(username, input_username) == 0 && strcmp(password, input_password) ==
0)
printf("Authentication successful!\n");
break;
} else
printf("Invalid username or password. Please try again.\n");
int choice;
float balance = 3000; // Initial balance
// ATM menu
while (1) {
printf("\nATM Menu:\n");
printf("1. Check Balance\n");
printf("2. Deposit\n");
printf("3. Withdraw\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Your balance: $%.2f\n", balance);
scanf(“%f” ,&Check Balance);
break;
case 2:
float deposit_amount;
printf("Enter deposit amount: $");
scanf("%f", &deposit_amount);
balance += deposit_amount;
printf("Deposit successful. Your new balance: $%.2f\n", balance);
break;
case 3:
float withdraw_amount;
printf("Enter withdrawal amount: $");
scanf("%f", &withdraw_amount);
if (withdraw_amount > balance) {
printf("Insufficient balance!\n");
} else {
balance -= withdraw_amount;
printf("Withdrawal successful. Your new balance: $%.2f\n", balance);
break;
case 4:
printf("Thank you for using the ATM. Goodbye!\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
return 0;
OUTPUT :
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 2.
Enter Deposit amount: $Deposit successful. Your new balance: $3000.00
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 3.
Enter withdrawal amount: $Withdrawal successful. Your new balance: $1000.00
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 1.
Enter Check Balance: $ Check Balance. Your new balance: $1000.00
FLOW CHART OF SWITCH STATEMENT :
SYANTX OF SWITCH STATEMENT :
C program for sorting the array elements by bubble
sort and searching the array elements by binary
search
#include <stdio.h>
// Function to perform bubble sort
void bubbleSort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
// Function to perform binary search
int binarySearch(int arr[], int l, int r, int x) {
if (r >= l) {
int mid = l + (r - l) / 2;
// If the element is present at the middle itself
if (arr[mid] == x)
return mid;
// If element is smaller than mid, then it can only be present in
left subarray
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
// Else the element can only be present in right subarray
return binarySearch(arr, mid + 1, r, x);
}
// If the element is not present in the array
return -1;
}
int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr)/sizeof(arr[0]);
int i, x;
printf("Array before sorting:\n");
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
bubbleSort(arr, n);
printf("Array after sorting:\n");
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
printf("Enter the element to search: ");
scanf("%d", &x);
int result = binarySearch(arr, 0, n - 1, x);
if (result == -1)
printf("Element not present in the array\n");
else
printf("Element found at index %d\n", result);
return 0;
}
OUTPUT :
Array before sorting:
64 34 25 12 22 11 90
Array after sorting:
11 12 22 25 34 64 90
Enter the element to search: 64
Element found at index 5
Array before sorting:
64 34 25 12 22 11 90
Array after sorting:
11 12 22 25 34 64 90
Enter the element to search: 09
Element not present in the array