PBL Assignment 1-5
PBL Assignment 1-5
Date: 10/01/2024
Assignment No: 1
Problem Statement: Design a program to simulate a basic ATM machine function allowing users to check
balance, deposit, and withdraw funds.
Source Code:
#include <stdio.h>
void main()
scanf("%d", &pin);
if (pin != 2004)
do
printf("6. Quit\n");
printf("******************?**************************?*\n\n");
scanf("%d", &choice);
switch (choice)
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
scanf("%lu", &withdraw);
if (withdraw % 100 != 0)
else
break;
case 5:
scanf("%lu", &deposit);
break;
case 6:
break;
default:
fflush(stdin);
scanf("%c", &transaction);
k = 1;
} while (!k);
Sample Output:
DR. D. Y. PATIL SCHOOL OF SCIENCE & TECHNOLOGY
DR. D. Y. PATIL VIDYAPEETH, PUNE
(Deemed to be University)
(Accredited (3rd cycle) by NAAC with a CGPA of 3.64 on four-point scale at ‘A++’ Grade)
(Declared as Category - I University by UGC Under Graded Autonomy Regulations, 2018)
(An ISO 9001: 2015 and 14001:2015 Certified University and Green Education Campus)
Date: 18/01/2024
Assignment No: 2
Problem Statement: Implement a basic to-do list program with add, delete, and display functionalities.
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char task[100];
} Task;
Task todoList[MAX_TASKS];
int numTasks = 0;
void displayTasks() {
if (numTasks == 0) {
} else {
printf("To-Do List:\n");
for (int i = 0; i < numTasks; i++) {
void addTask() {
if (numTasks == MAX_TASKS) {
return;
numTasks++;
void deleteTask() {
int taskIndex;
if (numTasks == 0) {
return;
}
displayTasks();
scanf("%d", &taskIndex);
return;
numTasks--;
int main() {
int choice;
do {
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
displayTasks();
break;
case 2:
addTask();
break;
case 3:
deleteTask();
break;
case 4:
break;
default:
return 0;
Sample Output:
1. Display tasks
2. Add task
3. Delete task
4. Exit
Enter your choice: 2
1. Display tasks
2. Add task
3. Delete task
4. Exit
To-Do List:
1. 50000
1. Display tasks
2. Add task
3. Delete task
4. Exit
Date: 29/01/2024
Assignment No: 3
Problem Statement: Design a simple quiz application that asks multiple-choice questions.
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_QUESTIONS 5
typedef struct {
char question[256];
char options[4][64];
int correct_option;
} Question;
void displayQuestion(Question q)
printf("%s\n", q.question);
int main()
srand(time(NULL));
Question original_questions[MAX_QUESTIONS] =
2 },
2 },
1 },
2 },
2}
};
Question questions[MAX_QUESTIONS];
memcpy(questions, original_questions,
sizeof(original_questions));
int score = 0;
displayQuestion(current_question);
int user_answer;
scanf("%d", &user_answer);
if (checkAnswer(current_question,
user_answer))
printf("Correct!\n");
score++;
else
"%d. %s\n",
current_question.correct_option,
current_question.options
[current_question.correct_option
- 1]);
else
questions[random_index]
= questions[num_questions - 1];
num_questions--;
"score: %d/%d\n",
score, MAX_QUESTIONS);
return 0;
}
Sample Output:
1. Drift
2. Pride
3. Flock
4. Drove
Correct!
1. Sydney
2. California
3. New York
4. Paris
Correct!
1. Owl
2. Ostrich
3. Kingfisher
4. Woodpecker
Correct!
1. 7
2. 8
3. 6
4. 5
Enter your answer (1-4): 2
Correct!
Where does the President of the United States live while in office?
2. The Parliament
3. House of Commons
4. Washington DC
Correct!
Date: 02/02/2024
Assignment No: 4
Problem Statement: Develop a basic currency converter between different currencies.
Source Code: z
#include <stdio.h>
int main()
float amount;
int choice;
printf("\nEnter 1: Ruppe");
printf("\nEnter 2: Dollar");
printf("\nEnter 3: Pound");
printf("\nEnter 4: Euro");
scanf("%f", &amount);
switch (choice)
break;
break;
break;
break;
//Default case
default:
printf("\nInvalid Input");
return 0;
Sample Output:
Enter 1: Ruppe
Enter 2: Dollar
Enter 3: Pound
Enter 4: Euro
20000
Date: 09/02/2024
Assignment No: 5
Problem Statement:
Source code:
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define COMPUTER 1
#define HUMAN 2
#define SIDE 3
struct Move {
};
char player = 'x', opponent = 'o';
if (board[i][j] == '_')
return true;
return false;
if (b[row][0] == b[row][1]
if (b[row][0] == player)
return +10;
return -10;
if (b[0][col] == player)
return +10;
return -10;
if (b[0][0] == player)
return +10;
return -10;
if (b[0][2] == player)
return +10;
return -10;
return 0;
}
int minimax(char board[3][3], int depth, bool isMax)
if (score == 10)
return score;
if (score == -10)
return score;
if (isMovesLeft(board) == false)
return 0;
if (isMax) {
if (board[i][j] == '_') {
board[i][j] = player;
int val
best = val;
board[i][j] = '_';
return best;
else {
if (board[i][j] == '_') {
board[i][j] = opponent;
int val
best = val;
board[i][j] = '_';
return best;
bestMove.row = -1;
bestMove.col = -1;
if (board[i][j] == '_') {
board[i][j] = player;
board[i][j] = '_';
bestMove.row = i;
bestMove.col = j;
bestVal = moveVal;
return bestMove;
printf("\n\n");
board[0][1], board[0][2]);
printf("\t\t\t--------------\n");
printf("\t\t\t--------------\n");
board[2][1], board[2][2]);
void showInstructions()
printf("\t\t\t Tic-Tac-Toe\n\n");
"and play\n\n");
printf("\t\t\t 1 | 2 | 3 \n");
printf("\t\t\t--------------\n");
printf("\t\t\t 4 | 5 | 6 \n");
printf("\t\t\t--------------\n");
printf("\t\t\t 7 | 8 | 9 \n\n");
printf("-\t-\t-\t-\t-\t-\t-\t-\t-\t-\n\n");
srand(time(NULL));
for (int i = 0; i < SIDE; i++) {
moves[i] = i;
moves[i] = moves[randIndex];
moves[randIndex] = temp;
if (whoseTurn == COMPUTER)
else
}
int rowCrossed(char board[][SIDE])
if (board[i][0] == board[i][1]
return 1;
return 0;
if (board[0][i] == board[1][i]
return 1;
return 0;
if ((board[0][0] == board[1][1]
|| (board[0][2] == board[1][1]
return 1;
return 0;
|| diagonalCrossed(board));
char board[SIDE][SIDE];
showInstructions();
int moveIndex = 0, x, y;
if (whoseTurn == COMPUTER) {
char tempBoard[3][3];
if (board[i][j] == 'X') {
tempBoard[i][j] = 'x';
tempBoard[i][j] = 'o';
else {
tempBoard[i][j] = '_';
x = thisMove.row;
y = thisMove.col;
board[x][y] = COMPUTERMOVE;
COMPUTERMOVE, x, y);
showBoard(board);
moveIndex++;
whoseTurn = HUMAN;
int move;
scanf("%d", &move);
continue;
x = (move - 1) / SIDE;
y = (move - 1) % SIDE;
board[x][y] = HUMANMOVE;
showBoard(board);
moveIndex++;
if (gameOver(board)) {
declareWinner(HUMAN);
return;
}
whoseTurn = COMPUTER;
else {
"again.\n",
move);
printf("It's a draw\n");
else {
if (whoseTurn == COMPUTER)
whoseTurn = HUMAN;
whoseTurn = COMPUTER;
declareWinner(whoseTurn);
}
int main()
playTicTacToe(COMPUTER);
return 0;
Sample Output:
Tic-Tac-Toe
1|2|3
--------------
4|5|6
--------------
7|8|9
O| |
--------------
| |
--------------
| |
O| |
--------------
|X|
--------------
| |
O|O|
--------------
|X|
--------------
| |
O|O|X
--------------
|X|
--------------
| |
O|O|X
--------------
O|X|
--------------
| |
O|O|X
--------------
O|X|
--------------
X| |
HUMAN has wo