Exercise Programs (Unit 1 C Programming)
Exercise Programs (Unit 1 C Programming)
Check whether the required amount can be withdrawn based on the available amount
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
// Structure declaration
struct acc_type
{
char bank_name[20];
char bank_branch[20];
char acc_holder_name[30];
int acc_number;
char acc_holder_address[100];
float available_balance;
};
struct acc_type account[20];
/*
printf("The above structure can be declared using
typedef like below");
option = getch();
printf("%c \n", option);
switch(option)
{
case '1': Create_new_account();
break;
case '2': Cash_Deposit();
break;
case '3': Cash_withdrawl();
break;
case '4': Account_information();
break;
case '5': return 0;
case '6': system("cls");
break;
default : system("cls");
printf("Please enter one of the options");
printf("(1/2/3/4/5/6) to continue \n ");
break;}
}
return 0;
}
//num_acc++;
}
void Account_information()
{
register int num_acc = 0;
//if (!strcmp(customer,account[count].name))
while(strlen(account[num_acc].bank_name)>0)
{
printf("\nBank name : %s \n" ,
account[num_acc].bank_name);
printf("Bank branch : %s \n" ,
account[num_acc].bank_branch);
printf("Account holder name : %s \n" ,
account[num_acc].acc_holder_name);
printf("Account number : %d \n" ,
account[num_acc].acc_number);
printf("Account holder address : %s \n" ,
account[num_acc].acc_holder_address);
printf("Available balance : %f \n\n" ,
account[num_acc].available_balance);
num_acc++;
}
}
void Cash_Deposit()
{
auto int acc_no;
float add_money;
while (acc_no=account[acc_no-1].acc_number)
{
account[acc_no-1].available_balance=
account[acc_no-1].available_balance+add_money;
printf("\nThe New balance for account %d is %f \n",
acc_no, account[acc_no-1].available_balance);
break;
}acc_no++;
}
while (acc_no=account[acc_no-1].acc_number)
{
account[acc_no-1].available_balance=
account[acc_no-1].available_balance-withdraw_money;
printf("\nThe New balance for account %d is %f \n",
acc_no, account[acc_no-1].available_balance);
break;
}acc_no++;
}
Menu-driven program to find the area of different shapes
#include <stdio.h>
void main()
int fig_code;
printf("-------------------------\n");
printf("-------------------------\n");
scanf("%d", &fig_code);
switch(fig_code)
case 1:
scanf("%f", &radius);
break;
case 2:
break;
case 3:
case 4:
scanf("%f", &side);
break;
default:
break;
}
}
-------------------------
1 --> Circle
2 --> Rectangle
3 --> Triangle
4 --> Square
-------------------------
Enter the Figure code
1
Enter the radius
30
Area of a circle = 2827.800049
-------------------------
1 --> Circle
2 --> Rectangle
3 --> Triangle
4 --> Square
-------------------------
Enter the Figure code
2
Enter the breadth and length
20 30
Area of a Reactangle = 600.000000
-------------------------
1 --> Circle
2 --> Rectangle
3 --> Triangle
4 --> Square
-------------------------
Enter the Figure code
3
Enter the base and height
45 80
Area of a Triangle = 1800.000000
-------------------------
1 --> Circle
2 --> Rectangle
3 --> Triangle
4 --> Square
-------------------------
Enter the Figure code
4
Enter the side
100
Area of a Square=1000
Output 1:
Enter start and end value
10
20
Output 2:
Enter start and end value
25
50