Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

YATHARTHA AARUSH PES1UG23AM358

1. Deposit or withdrawal code


#include <stdio.h>

float balance = 0;

void deposit(float amount) {


balance += amount;
printf("Deposited %.2f. New balance: %.2f\n", amount, balance);
}

void withdrawal(float amount) {


if (balance >= amount) {
balance -= amount;
printf("Withdrawn %.2f. New balance: %.2f\n", amount, balance);
} else {
printf("Insufficient balance.\n");
}
}

int main() {
char choice;
float amount;

printf("Initial balance: %.2f\n", balance);

do {
printf("\nMenu:\n");
printf("a) Deposit\n");
printf("b) Withdrawal\n");
printf("x) Exit\n");
printf("Enter your choice: ");
scanf(" %c", &choice);

switch (choice) {
case 'a':
printf("Enter amount to deposit: ");
scanf("%f", &amount);
deposit(amount);
break;
case 'b':
printf("Enter amount to withdraw: ");
scanf("%f", &amount);
withdrawal(amount);
break;
case 'x':
printf("Exiting...\n");
break;
default:
printf("Invalid choice.\n");
}
} while (choice != 'x');

return 0;
}
2. Monthly Interest Calculation of a Savings Account
#include <stdio.h>

int main() {
double principal, rate, time, interest;

// Input principal amount, interest rate, and time period


printf("Enter principal amount: ");
scanf("%lf", &principal);
printf("Enter annual interest rate (in percentage): ");
scanf("%lf", &rate);
printf("Enter time period (in years): ");
scanf("%lf", &time);

// Convert annual interest rate to monthly rate


rate /= 100; // Convert percentage to decimal
double monthly_rate = rate / 12;

// Calculate monthly interest


interest = principal * monthly_rate * time;

// Print the result


printf("Monthly interest: %.2f\n", interest);

return 0;
}

Fixed Deposit Maturity amount and Interest Calculation


#include <stdio.h>
#include <math.h>

int main() {
double principal, rate, time, interest, maturity_amount;

// Input principal amount, interest rate, and time period


printf("Enter principal amount: ");
scanf("%lf", &principal);
printf("Enter annual interest rate (in percentage): ");
scanf("%lf", &rate);
printf("Enter time period (in years): ");
scanf("%lf", &time);

// Convert annual interest rate to decimal


rate /= 100;

// Calculate interest and maturity amount using simple interest formula


interest = (principal * rate * time);
maturity_amount = principal + interest;

// Print the result


printf("Interest: %.2f\n", interest);
printf("Maturity Amount: %.2f\n", maturity_amount);

return 0;
}

EMI Calculation for Home Loan


#include <stdio.h>
#include <math.h>

int main() {
double principal, rate, time, emi;
int months;

// Input principal amount, interest rate, and time period


printf("Enter principal amount: ");
scanf("%lf", &principal);
printf("Enter annual interest rate (in percentage): ");
scanf("%lf", &rate);
printf("Enter time period (in years): ");
scanf("%lf", &time);

// Convert annual interest rate to decimal and time period to months


rate /= 12 * 100; // Monthly interest rate
months = time * 12; // Total number of payments

// Calculate EMI using the formula: EMI = [P * R * (1+R)^N] / [(1+R)^N - 1]


emi = (principal * rate * pow(1 + rate, months)) / (pow(1 + rate, months) - 1);

// Print the result


printf("EMI for Home Loan: %.2f\n", emi);

return 0;
}

You might also like