c Programming Lab 2022
c Programming Lab 2022
TECHNOLOGY
NAME :
REG.NO. :
YEAR /SEM :
CAPE INSTITUTE OF TECHNOLOGY
BONAFIDE CERTIFICATE
NAME :
REG.NO. :
PROGRAMME :
DEPARTMENT :
SEMESTER :
Mr/Ms of semester
3. Nested if-else
4. Switch statement
5. While loop
6. For loop
7. If ladder
8. Using arrays
9. Using string
17. Banking
Date :
AIM:
To write a c program using I/O statements and expression
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values to the respective
variables
STEP 4: Use operators to perform calculations wherever required
STEP 5: Print the output message with the final values
STEP 6: END
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
float totamt, amount, subtot, disamt, taxamt,
quantity, value, discount, tax;
clrscr();
printf(“\n Discounted
Total:%f”,subtot);
Output:
Enter the quantity of item
sold: 10
RESULT:
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the character name and the number of values to be
allotted
STEP 3: Enter the data type and the variables required
STEP 4: Print messages for the user to enter their name and age
STEP 5: Use if statement to check if the condition is true. If false,
use else statement.
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
char
name[50];
int age;
clrscr();
printf(“\n Enter the name of
the candidate:”);
scanf(“%s”,name);
printf(“\n Enter the age of
the candidate:”);
scanf(“%d”,&age);
if(age>=18)
{
printf(“\n %s is eligible for vote”,name);
}
else
{
printf(“\n %s is not eligible for vote”,name);
}
getch();
}
10
Output-1:
Enter the name of the
candidate: Ram
Output-2:
Enter the name of the
candidate: Raj
RESULT:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values to the respective
variables
STEP 4: Using nested if-else block, check if the first condition is true. Then it moves to the if condition
within the first if block and so on.
STEP 5: If the first if condition is false, it moves to the else block and the statements within it.
STEP 6: END
Source Code:
#include<std
io.h>
#include<con
io.h> void
main()
{
int
year;
clrsc
r();
printf(“\n Enter
a year:”);
scanf(“%d”,&year)
; if((year%4)==0)
{
if((year%100)==0)
{
if((year%400)==0)
{
printf(“\n %d is a leap year”,year);
}
else
{
13
printf(“\n %d is not a leap year”,year);
}
}
else
14
{
printf(“\n %d is a leap year”,year);
}
}
else
{
printf(“\n %d is not a leap year”,year);
}
getch();
}
Output-1:
Enter a year: 1700
1700 is not a leap
year
Output-2:
Enter a year:
2016 2016 is a
leap year
RESULT:
15
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values and enter a
choice of operation
STEP 4: Assign a variable to the switch statements.
STEP 5: Assign operating conditions for each cases and print messages
accordingly
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, result,
sq1, sq2, ch;
clrscr();
printf(“\n Enter two
integers:”); scanf(“%d
%d”,&a,&b);
printf(“\n 1.Add 2.Subtract 3.Multiply
4.Divide 5.Square”);
printf(“\n Enter the choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
result=a+b;
printf(“\n Sum=%d”,result);
brea
k;
case
2:
result=a-b;
17
printf(“\n Difference=%d”,result);
break;
case 3:
result=
a*b;
18
printf(“\n Multiplication=%d”,result);
break;
case 4:
result=a/b;
printf(“\n
Division=%d”,result);
break;
case 5:
sq1=a*a;
sq2=b*b;
printf(“\n
Square=%d”,sq1);
printf(“\n
Square=%d”,sq2); break;
}
getch();
}
Output:
Enter two integers: 2 3
the choice: 1
Sum=5
RESULT:
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values to the
respective variables
STEP 4: Set while loop parameters
STEP 5: Use conditional statements to print the required value
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, orgnum, r,
result=0;
clrscr();
printf(“\n Enter a three
digit integer:”);
scanf(“%d”,&n);
orgnum=n;
while(orgnum
!=0)
{
r=orgnum%1
0;
result+=r*
r*r;
orgnum/=10
;
}
if(result==n)
{
printf(“\n %d is an Armstrong number”,n); 20
}
else
{
printf(“\n %d is not an Armstrong number”,n);
}
21
getch();
}
Output:
Enter a year: 153
153 is an Armstrong number.
RESULT:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values to the
respective variables
STEP 4: Set for loop initial value, test condition and increment
STEP 5: Print the statements as pet the for loop conditions
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int getWeight(int);
int nums[15],
ws[15], i, j, t, n;
clrscr();
printf(“\n Enter the
array size:”);
scanf(“%d”,&n);
printf(“\n Enter the
numbers:”);
for(i=0;i<n;i++)
{
scanf(“%d”,&nums[i]);
}
for(i=0;i<n;i++)
{
ws[i]=getWeight(nums[i]);
}
printf(“\n Before Sorting:”);
for(i=0;i<n;i++)
{
23
printf(“%d:%d\t”,nums[i],ws[i]);
} 24
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(ws[j]>ws[j+1])
{
t=ws[j+1];
ws[j+1]=ws[j]
; ws[j]=t;
t=nums[j+1];
nums[j+1]=num
s[j];
nums[j]=t;
}
}
}
printf(“\n After Sorting:”);
for(i=0;i<n;i++)
{
printf(“%d:%d\t”,nums[i],ws[i]);
}
getch();
}
int getWeight(int n)
{
int w=0;
float
root=sqrt(n)
;
if(root==cei
l(root))
w+=5;
if(n%4==0&&n%6=
=0) w+=4;
if(n%2=
=0)
w+=3; 25
return w;
}
26
Output:
Before Sorting:
10:3 36:12 54:3 89:0 12:7 27:0
After Sorting:
89:0 27:0 10:3 54:3 2:7 36:12
RESULT:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values to the
respective variables
STEP 4: Using if condition, check if the statement is true.
STEP 5: If false, it moves to else if conditions.
STEP 6: If both if and else if conditions are false, it move to else block.
STEP 7: END
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
float
height;
clrscr()
;
printf(“\n Enter the height (in
centimeters):”);
scanf(“%f”,&height);
if(height<150.0)
{
printf(“\n Dwarf”);
}
else if((height>=150.0)&&(height<=165.0))
{
printf(“\n Average Height”);
}
else if((height>=165.0)&&(height<=195.0))
{
printf(“\n Taller”);
}
else 28
{
printf(“\n Abnormal height”);
29
}
getch();
}
Output:
Enter the height (in
centimeters): 170 Taller
RESULT:
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type, array name and value
STEP 3: Print messages for the user to enter values
STEP 4: Use nested for loops to set the iteration parameters
STEP 5: Print the calculated values
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int weight[5][5],
n, i, j, bmi;
clrscr();
printf(“\n Enter the
upper limit:”);
scanf(“%d”,&n);
printf(“\n Enter Weight and Height:”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf(“%d”,&weight[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(“%d\t”,weigh
t[i][j]);
31
bmi=weight[i][j]*we
ight[i][j];
printf(“\n
BMI:%d”,bmi);
32
}
}
getch();
}
Output:
Enter the upper limit:
2 Enter Weight and
Height:
53 5.5
65 5.5
53 5.5
65 5.5
BMI:18.859083
BMI:23.129063
RESULT:
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter string data type, value and array allotment
STEP 3: Print messages for the user to type the sting values
STEP 4: Use while loop to set condition. Use decision making
statements to print the desired output
STEP 5: Return the value based on the given condition
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
voidmain()
{
void
reverseString(ch
ar); bool
isAlphabet(char)
; chars[100];
clrscr();
printf(“\n Enter the input string and
special character:”); scanf(“%s”,&s);
printf(“\n Input String:%s”,s);
reseverseString(s);
printf(“\n Output String:%s”,s);
getch();
}
bool isAlphabet(char x)
{
return ((x>=’A’ && x<=’Z’)||(x>’a’&&x<=’z’));
}
void reverseString(char s[])
{ 34
int
r=strlen(s)-
1, l=0;
while(l<r)
35
{
if(!isAlphabet(s[
l]) l++;
else
if(!isAlphabet(s[r]))
r--;
else
{
swap(s[l],s[r])
; l++;
r--;
}
}
}
Output:
RESULT:
36
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Print messages to get the input from the user
STEP 3: Use while loop to set the initial values
STEP 4: Use arithmetic operators to perform arithmetic operations
STEP 5: Return the values based on the limits
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int
convertBinaryToDecimal(lon
g int n); int
convertDecimalToOctal(int
dn); voidmain()
{
long int
n,dn;
clrscr();
printf(“\n Enter a
binary number:”);
scanf(“%ld”,&n);
printf(“\n %ld in binary=%d in
decimal”,n,convertBinaryToDecimal(n));
printf(“\n Enter a decimal number:”);
scanf(“%d”,&dn);
printf(“\n %ld in decimal=%d in octal”,dn,convertDecimalToOctal(dn));
getch();
}
int convertBinaryToDecimal(long int n)
{
38
int
dn=0,i=0,remaind
er; while(n!=0)
{
remainder=n%10;
39
n/=10;
dn+=remainder*pow(2,i)
;
++I;
}
return dn;
}
int convertDecimalToOctal(int dn)
{
int onum=0,i=1;
while(dn!=0)
{
onum+=(dn%8)*I;
dn/=8;
i*=10;
}
return onum;
}
Output:
Enter a binary number:
101 101
in binary=5 in decimal
in decimal=116 in octal
40
RESULT:
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and array length
STEP 3: Print messages for the user to enter the string value
STEP 4: Use for, while or do-while loop to set the initial value, test condition, increment and
parameters
STEP 5: Use if-else condition to print the output
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
#define MAX 100
void main()
{
char
str[MAX]={0}
; int I;
clrscr();
printf(“\n Enter a string:”);
scanf(“%s”,&str);
for(i=0;str[i]!=’\0’;i++)
{
if(i==0)
{
if(str[i]>=’a’&&str[i]<=’z’
)
str[i]=str
[i]-32;
continue;
}
if(str[i]==’ ’)
{
++i;
if(str[i]>=’a’&&str[i]<=’z’)
{ 42
str[i]=str
[i]-32;
continue;
43
}
}
else
{
if(str[i]>=’A’&&str[i]<=’Z’)
str[i]=str[i]+32;
}
}
Output-1:
Enter a string: c programming
laboratory
Output-2:
Enter a string: C PROGRAMMING
LABORATORY
RESULT:
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variable
STEP 3: Print message to get number of disks
STEP 4: Assign an integer and three character values respectively
STEP 5: Use if condition to check the statement. Print the procedure if the condition checks out as true
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void
towers(int,char,char,char)
; void main()
{
int num;
clrscr();
printf(“\n Enter the number of
disks:”); scanf(“%d”,&num);
printf(“\n The sequence of moves involved in the
Towers of Hanoi are:”); towers(num,’A’,’C’,’B’);
getch();
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if(num==1)
{
printf(“\n Move disk-1 from peg %c to peg %c”,frompeg,topeg);
}
towers(num-1, frompeg, auxpeg, topeg);
printf(“\n Move disk %d from peg %c to peg %c”,num,frompeg,topeg);
47
towers(num-1,auxpeg,topeg,frompeg);
}
0utput:
Enter the number of disks: 3
The sequence of moves involved in the Tower
of Hanoi are: Move disk 1 from peg A to peg
C.
Move disk 2 from peg A to
peg B.
Move disk 1 from peg C to
peg B.
Move disk 3 from peg A to
peg C.
Move disk 1 from peg B to
peg A.
Move disk 2 from peg B to
peg C.
Move disk 1 from peg A to
peg C.
48
RESULT:
AIM:
To write a c program using Sorting
ALGORITHEM:
STEP 1: START
STEP 2: Enter the data type and the variables required
STEP 3: Print messages for the user to assign values to the
respective variables
STEP 4: Use for loop to set the initial value, test condition & increment
STEP 5: Use void sort function to perform the sorting
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
void sort(int
m, int x[]); int
i,n;
int
marks[10]
;
clrscr();
printf(“\n Enter
Upper Limit:”);
scanf(“%d”,&n);
for(j=1;j<=m-i;j++)
{
if(x[j-1]>=x[j])
{
t=x[j-1];
x[j-1]=x[j];
x[j]=t;
}
}
}
}
Output:
Enter Upper Limit: 5
Enter n values: 3 2 1
5 4
After Sorting: 1 2 3 4 5
53
RESULT:
ALGORITHEM:
STEP 1: START
STEP 2: Use the string directories and data types
STEP 3: Print messages for the user to assign values to the
respective variables
STEP 4: Use structure function wherever necessary
STEP 5: Print the outputs accordingly
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct employee
{
int
empId;
charname[3
2];
int basic,
hra, da, ma;
int pf,
insurance;
float gross,
net;
}
void main()
{
int
i,ch,num,flag,em
pID; struct
employee *e1;
clrscr();
printf(“\n Enter the number of 57
employees:”); scanf(“%d”,&num);
e1=(struct employee*)malloc(sizeof(struct
employee)*num); printf(“\n Enter your
input for every employee:”);
for(i=0;i<num;i++)
{
printf(“\n 58
Employee ID:”);
scanf(“%d”,&e1[i]
.empId);
printf(“\n Employee
Name:”);
fgets(e1[i].name,32,stdin
);
e1[i].name[strlen(e1[i].n
ame)-1]=’\0’; printf(“\n
Basic Salary:”);
scanf(“%d”,&e1[i]
.basic);
printf(“\n
HRA:”);
scanf(“%d”,&e1[i]
.hra); printf(“\n
DA:”);
scanf(“%d”,&e1[i]
.da);
printf(“\n Medical
Allowance:”);
scanf(“%d”,&e1[i].ma)
;
printf(“\n
PF:”);
scanf(“%d”,&e1[
i].pf);
printf(“\nInsur
ance:”);
scanf(“%d”,&e1[i].insurance);
}
for(i=0;i<num;i++)
{
e1[i].gross=e1[i].basic+(e1[i].hra*e1[i].basic)/100+(e1[i].da*e1[i].ba
sic)/100+(e1[i].ma*e1[i
].basic)/100;
e1[i].net=e1[i].gross-/(e1[i].pf+e1[i].insurance);
} 59
while(1)
{
printf(“\n Enter Employee ID to
get payslip:”);
scanf(“%d”,&empID);
flag=0;
for(i=0;i<nu
m;i++)
{
if(empID==e1[i].empId)
{
printSalary(
e1[i]);
flag=1;
} 60
if(!flag)
{
printf(“\n No Record Found!!”);
}
printf(“\n Do you want to
continue(1/0):”);
scanf(“%d”,&ch);
if(!ch)
{
break;
}
}
getch();
}
void printSalary(struct employeee1)
{
printf(“\n Salary Slip of
%s:”,e1.name); printf(“\n
Employee ID:%d”,e1.empId);
printf(“\n
BasicSalary:%d”,e1.basic);
printf(“\n House Rent
Allowance:%d”,e1.hra);
printf(“\n Dearness
Allowance:%d”,e1.da);
printf(“\n Medical
Allowance:%d”,e1.ma);
printf(“\n Gross
Salary:%.2f”,e1.gross);
printf(“\n Deductions:”);
printf(“\n Provident
Fund:%d”,e1.pf);
printf(“\n
Insurance:%d”,e1.insurance
);
printf(“\n Net Salary:%.2f Rupees”,e1.net);
} 61
Output:
Enter the number of
employees: 2
Employee ID:
9293
Employee Name:
Ram
Basic Salary:
250000
HRA: 50000 62
DA: 4000
Insurance: 6000
Employee ID:
9282
Employee
Name: Raj
Basic
Salary: 150000
HRA:25000
DA: 3000
Insurance: 2500
Insurance: 2500
Net Salary: 4444828.00
continue(1/0):
RESULT:
65
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Use the string directories and data types
STEP 3: Print messages for the user to assign values to the respective variables
STEP 4: Use structure function wherever necessary. Use for, do, do...while loops.
STEP 5: Print the outputs accordingly
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
struct student
{
int
sub1;
int
sub2;
int
sub3;
int
sub4;
int
sub5;
}
void main()
{
struct
student
s[10]; int
i,total=0;
clrscr();
for(i=0;i<=1;
i++)
67
{
printf(“\n Enter Marks in Five Subjects:”);
scanf(“%d%d%d%d%d”,&s[i].sub1,&s[i].sub2,&s[i].sub3,&s[i].sub4,&
s[i].sub[5]); total=s[i].sub1+ s[i].sub2+ s[i].sub3+ s[i].sub4+
s[i].sub5;
printf(“\n Total Marks of s[%d] Student=%d”,i,total);
68
}
getch();
}
Output:
Enter Marks in Five Subjects: 45 78
45 35 71 Total
Marks of s[0]Student=274
RESULT:
69
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Use the string directories and data types
STEP 3: Print messages for the user to assign values to the respective variables
STEP 4: Use structure function wherever necessary. Use switch case statements.
STEP 5: Print the outputs accordingly
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct person
{
char
name[20];
long
telno;
}
void main()
{
char
choice;
clrscr()
;
while(1)
{
printf(“\n**********TELEPHONE
DIRECTORY*********\n”); printf(“\n 1.Append
Record”);
printf(“\n 2.Find Record”);
printf(“\n 3.Read
71
all Record”);
printf(“\n 4.Exit”);
fflush(stdin);
choice=getc
he();
swictch(cho
ice)
{
case ‘1’: 72
appendDat
a();
break;
case ‘2’:
findDat
a();
break;
case‘3’:
showAllDat
a();
break;
case ‘4’:
exit(1);
}
}
getch();
}
void appendData()
{
FILE *fp;
struct person obj;
fp=fopen(“data.txt”,”a”);
printf(“\n ******Add
Record******\n”); printf(“\n
EnterName:”);
scanf(“%s”,obj.name);
printf(“\n Enter
Telephone No:”);
scanf(“%ld”,&obj.teno)
;
fprintf(fp,”%20s %7ld”,obj.name,obj.telno);
fclose(fp);
}
void showAllData()
{
FILE *fp;
struct person obj; 73
fp=fopen(“data.txt”,”r”);
printf(“\n ****Display All
Records****\n”); printf(“\n
\t\\t Name\t\t Telephone
No.”);
while(!feof(fp)) 74
{
fscanf(fp,”%20s
%7ld”,obj.name,&obj.telno);
printf(“\n %20s
%30ld”,obj.name,obj.telno);
}
fclose(fp);
}
void findData()
{
FILE *fp;
struct
person obj;
char
name[20];
int
totrec=0;
fp=fopen(“data.txt”,”r”);
printf(“\n ****Display Specific
Records****”); printf(“\n Enter
Name:”);
scanf(“%s”,&name);
while(!feof(fp))
{
fscanf(fp,”%20s %7ld”,obj.name,&obj.telno);
if(strcmpi(obj.name,name)==0)
{
printf(“\n Name:%s”,obj.name);
printf(“\n Telephone No:%ld”,obj.telno);
totrec++;
}
}
if(totrec==0)
{
printf(“\n No Data Found”);
}
else 75
{
printf(“\n ===Total %d Record Found ===”,totrec);
} 76
fclose(fp);
}
Output:
**********TELEPHONE
DIRECTORY********* 1.Append
Record
2.Find
Record
3.Read all
Record
4.Exit
Enter your choice: 1
***Add
Record***
Enter Name:
Ram
Enter Telephone No: 24563982
**********TELEPHONE
DIRECTORY********* 1.Append
Record
2.Find
Record
3.Read all
Record
4.Exit
Enter your choice: 1
***Add
Record***
Enter Name:
Raj
Name TelephoneNo
Ram 24563982
Raj 24563985
**********TELEPHONE DIRECTORY*********
1.Append Record
2. Find Record
RESULT:
Date:
AIM:
To write a c program using Banking
ALGORITHEM:
STEP 1: START
STEP 2: Use the string directories and data types
STEP 3: Print messages for the user to assign values to the respective variables
STEP 4: Use structure function wherever necessary. Use switch case statements.
STEP 5: Print the outputs accordingly
STEP 6: END
Source Code:
#include<stdio.h>
#include<conio.h>
void creation();
void deposit();
void withdraw();
void lowbal();
int
a=0,i=1001
; struct
bank
{
int no;
char
name[20];
float bal;
float dep;
}s[100];
void main()
{
int
ch;
clrsc
r();
do
{
printf(“\n
***************”); 80
printf(“\n Banking”);
printf(“\n ***************“);
printf(“\n 1.Create New Account”);
printf*”\n 2.Cash Deposit”);
printf(“\n 3.Cash Withdraw”); 81
printf(“\n 4.Low
Balance Enquiry”);
printf(“\n 5.Exit”);
printf(“\n Enter your
choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
creatio
n();
break;
case 2:
deposi
t();
break;
case
3:
withdraw
();
break;
case4:
lowbal
();
break;
case5:
break
;
defau
lt:
printf(“\n Choose a valid option!!”);
}
while(ch!=5);
getch();
}
void creation()
{ 82
printf(“\n**************”);
printf(“\n New Account
Creation”);
printf(“\n*************
*”);
printf(“\n Your Account
Number:%d”,i); s[a].no=i;
printf(“\n Enter your name:”);
scanf(“%s”,s[a].name); 83
printf(“\n Your Deposit is Minimum Rs.500”);
s[a].dep=
500; a++;
i++;
}
void deposit()
{
int n,
b=0, m=0;
floataa;
printf(“\n
**************”);
printf(“\n Cash
Deposit”);
printf(“\n **************”);
printf(“\n Enter your
Account Number:”);
scanf(“%d”,&no);
for(b=0;b<i;b++)
{
if(s[b].no
==no) m=b;
}
if(s[m].no==no)
{
printf(“\n Account Number
:%d”,s{[m].no); printf(“\n
Name : %s;,s[m].name);
printf(“\n Deposit :
%f”,s[m].dep);
printf(“\n Deposited
Amount : “);
scanf(“%f”,&aa);
s[m].dep+=aa;
printf(“\nThe Balance in Account is: %f”,s[m].dep);
}
else 84
{
printf(‘\n ACCOUNT Number is invalid”);
}
}
void withdraw() 85
{
int no,
b=0, m=0;
float aa;
printf(“\n
********************”);
printf(“\n Cash
Withdraw”);
printf(“\n ********************”);
printf(“\n Enter your
account number:”);
scanf(“%d”,&no);
for(b=0;b<i;b++)
{
if(s[b].no
==no) m=b;
}
if(s[m].no==no)
{
printf(“\n Account
Number:%d”,s[m].no);
printf(“\n
Name:%s”,s[m].name);
printf(“\n
Deposit:%f”,s[m].dep);
printf(“\n Withdraw
Amount:”);
scanf(“%f”,&aa);
if(s[m].dep<aa+500)
{
printf(“\n Cannot Withdraw your account has minimum balance”);
}
else
{
s[m].dep-=aa;
printf(“\n Balance amount in account is %f”,s[m].dep);
85
} 86
}
else
printf(“\n Invalid”);
}
void lowbal()
86
{ 87
int no,
b=0, m=0;
floataa;
printf(“\n ***************”);
printf(“\n Following Account Holder’s
Balance<1000”); printf(“\n
***************”);
for(b=0;b<a;b++)
{
if(s[b].dep<1000)
{
printf(“\n Account
Number:%d”,s[b].no);
printf(“\n
Name:%s”,s[b].name);
}
}
}
Output:
*******************
**** BANKING
*******************
**** 1.Create New
Account 2.Cash
Deposit
3. Cash
Withdraw 4.Low
Balance Enquiry
5.Exit
Enter your
choice:1
Account Number
:1001 Name :viji
Your Deposit is minimum Rs. 500
*******************
**** BANKING
87
******************* 88
**** 1.Create New
Account 2.Cash
Deposit
3.CashWithdraw
4.Low Balance
Enquiry
88
5.Exit 89
Enter your
choice :2
Account number
:1001
Deposit Amount:
100000 Net Amount
Rs. 10500.00
*******************
**** BANKING
*******************
**** 1.Create New
Account 2.Cash
Deposit
3.Cash Withdraw
4.Low Balance
Enquiry 5.Exit
Enter your
choice:1
Account Number
:1002 Name :
Kumar
Your Deposit is minimum Rs. 500
*******************
**** BANKING
*******************
**** 1.Create New
Account 2.Cash
Deposit
3.Cash Withdraw
4.Low Balance
Enquiry 5.Exit
Enter your choice:4
*********************
FOLLOWING ACCOUNT HOLDER’S BALANCE
*****************
**** Account
Number:1002
89
Name: Kumar 90
90
91
RESULT:
Thus the c program is executed successfully and the output is verified
91
92
92
93
93
94
95
Date:
AIM:
ALGORITHEM:
STEP 1: START
STEP 2: Use the string directories and data types
STEP 3: Print messages for the user to assign values to the
respective variables
STEP 4: Use structure function wherever necessary. Use else-if ladder.
STEP 5: Print the outputs accordingly
STEP 6: END
Source Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int seat;
char
name[15];
int age;
char gender;
struct node
*next;
}list, *ptr;
void
delet(ptr
a); void
add(ptr a);
void
printseat(ptr
temp); void
print(ptr a);
void main()
{
95
96
int i,
input;
ptr a;
clrscr(
);
a=(ptr)mallac(1*siz
eof(list)); a-
>next=NULL;
a->seat=0;
96
for(i=0;i<100;i++) 97
{
printf(“\n 1.To book a ticket”);
printf(“\n 2.For deleting a ticket”);
printf(\n 3.To print
the chart”);
printf(“\n 4.To exit
the loop”);
scanf(“%d”,&input);
if(input==1)
add(a);
else
if(input==2
) delet(a);
else
if(input==3
) print(a);
else
if(input==4
) break;
else
printf(“\n Not able to recognise the command”);
}
printf(“\n Thank You”);
getch();
}
void add(ptr a)
{
int
input,input
2; ptr
temp=NULL;
while(a->next!=NULL)
{
a=a->next;
}
if(a->seat>70)
97
{ 98
printf(“\n Train full”);
}
else if(a->seat>50)
98
{ 99
printf(“\n %d Waiting
available”,(a->seat)-50);
printf(“\n Enter 1 to exit and
0 to continue:”);
scanf(“%d”,&input2);
if(input2==1)
{
return;
}
}
temp=(ptr)malloc(1*siz
eof(list)); temp-
>next=NULL;
printf(“\n Enter
name:”);
scanf(“%s”,temp-
>name);
printf(“\n Enter
age:”);
scanf(“%d”,temp-
>age); printf(“\n
Enter gender:”);
scanf(“%c”,&temp-
>gender); temp-
>seat=(a->seat)+1;
printf(“\n Enter 1 to print
the ticket:”); printf(“\n 0
for not to print the
ticket:”);
scanf(“%d”,&input);
if(input==1)
{
printseat(temp);
}
a->next=temp;
}
void printseat(ptr temp)
99
{ 100
if(temp->seat>50)
printf(“WL=%d”,(temp-
>seat)-50); else
printf(“\n Confirm
seat=%d”,temp->seat);
printf(“\n Name=%s”,temp-
>name);
printf(“\n Gender=%c”,temp->gender);
10
0
printf(“\n Age=%d”,temp->age); 101
}
void print(ptr a)
{
a=a->next;
while(a!=N
ULL)
{
printf(“\n Seat number=%d, name=%s, age=%d, Gender=%c”,a->seat,a-
>name,a->age,a-
>gender
); a=a-
>next;
}
}
void delete(ptr a)
{
int
input;
ptr
temp;
a=a-
>next;
printf(“\n Enter the seat
number:”);
scanf(%d”,&input);
while(a!=NULL&&(a-
>seat)!=input) a=a-
>next;
if(a==NULL)
{
printf(“\n Cannot delete”);
}
temp=a;
a=a-
>next;
free(te
mp);
10
1
while(a!=NULL) 102
{
a->seat=a-
>seat-1;
a=a->next;
10
2
103
}
printf(“\n Seat deleted”);
}
Output:
1.To book a ticker
2.For deleting a
ticket
RESULT:
104