You are on page 1of 26

NAME REGISTER NUMBER

INDEX

EX. DATE NAME OF THE EXPERIMENT PAGE SIGNATURE


NO. NO.
1 Programs using, I/O statements and expressions.

2 Programs to find area and perimeter of circle.

3 Program to check whether a person is eligible to vote or not

4 Program to find largest of three given numbers.

5 To find whether the given year is leap year or Not.

6 Arithmetic operations.

7 Armstrong number.

8 Sort the numbers based on the weight.

9 Average height of persons.

10 Body Mass Index of the individuals.

11 Reverse of a given string.

12 Conversion of Decimal number into other bases.

13 Use built in function to find total number of words.

14 Program to capitalize the first word of each sentence

15 Program to replace a given word with another word.

16 Towers of Hanoi using Recursion.

17 Sorting using pass by reference.

18 Salary slips of employees.

19 Internal marks of students.

20 Telephone directory.

21 Banking Application

22 Railway reservation system

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

/* Program to print salary slip of employees*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* structure to store employee salary details */
struct employee {
int empId;
char name[32];
int basic, hra, da, ma;
int pf, insurance;
float gross, net;
};
/* prints payslip for the requested employee */
void printSalary(struct employee e1) {
printf("Salary Slip of %s:\n", e1.name);
printf("Employee ID: %d\n", e1.empId);
printf("Basic Salary: %d\n", e1.basic);
printf("House Rent Allowance: %d\n", e1.hra);
printf("Dearness Allowance: %d\n", e1.da);
printf("Medical Allowance: %d\n", e1.ma);
printf("Gross Salary: %.2f Rupees\n", e1.gross);
printf("\nDeductions: \n");
printf("Provident fund: %d\n", e1.pf);
printf("Insurance: %d\n", e1.insurance);
printf("\nNet Salary: %.2f Rupees\n\n", e1.net);
return;
}

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

int main() {
int i, ch, num, flag, empID;
struct employee *e1;
/* get the number of employees from the user */
printf("Enter the number of employees:");
scanf("%d", &num);
/* dynamically allocate memory to store employee salary details */
e1 = (struct employee *)malloc(sizeof(struct employee) * num);
/* get the employee salary details from the customer */
printf("Enter your input for every employee:\n");
for (i = 0; i <num; i++) {
printf("Employee ID:");
scanf("%d", &(e1[i].empId));
getchar();
printf("Employee Name:");
fgets(e1[i].name, 32, stdin);
e1[i].name[strlen(e1[i].name) - 1] = '\0';
printf("Basic Salary, HRA:");
scanf("%d%d", &(e1[i].basic), &(e1[i].hra));
printf("DA, Medical Allowance:");
scanf("%d%d", &(e1[i].da), &(e1[i].ma));
printf("PF and Insurance:");
scanf("%d%d", &(e1[i].pf), &(e1[i].insurance));
printf("\n");

}
/* gross and net salary calculation */

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

for (i = 0; i <num; i++) {


e1[i].gross = e1[i].basic +
(e1[i].hra * e1[i].basic) / 100 +
(e1[i].da * e1[i].basic) / 100 +
(e1[i].ma * e1[i].basic) / 100;
e1[i].net = e1[i].gross - (e1[i].pf + e1[i].insurance);
}
/* printing payslip for the given employee ID */
while (1) {
printf("Enter employee ID to get payslip:");
scanf("%d", &empID);
flag = 0;
for (i = 0; i <num; i++) {
if (empID == e1[i].empId) {
printSalary(e1[i]);
flag = 1;
}
}
if (!flag) {
printf("No Record Found!!\n");
}
printf("Do You Want To Continue(1/0):");
scanf("%d", &ch);
if (!ch) {
break;
}
} return 0; }

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

OUTPUT:

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

/*Internal marks calculation for the students*/


#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<=2;i++)
{
printf("\nEnter marks in 5 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("\nTotal marks of s[%d] student=%d",i,total);
}
getch();
}

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

OUTPUT:

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

/*Telephone directory*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Phonebook_Contacts
{
char FirstName[20];
char LastName[20];
char PhoneNumber[20];
} phone;
void AddEntry(phone * );
void DeleteEntry(phone * );
void PrintEntry(phone * );
void SearchForNumber(phone * );
int counter = 0;
char FileName[256];
FILE *pRead;
FILE *pWrite;
void main (void)
{
phone *phonebook;
int iSelection=0;
phonebook = (phone*) malloc(sizeof(phone)*100);
//int iSelection = 0;
if (phonebook == NULL)
{
printf("Out of Memory. The program will now exit");

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

}
else {}
do
{
printf("\n\t\t\tPhonebook Menu");
printf("\n\n\t(1)\tAdd Friend");
printf("\n\t(2)\tDelete Friend");
printf("\n\t(3)\tDisplay Phonebook Entries");
printf("\n\t(4)\tSearch for Phone Number");
printf("\n\t(5)\tExit Phonebook");
printf("\n\nWhat would you like to do? ");
scanf("%d", &iSelection);
if (iSelection == 1)
{
AddEntry(phonebook);
}
if (iSelection == 2)
{
DeleteEntry(phonebook);
}
if (iSelection == 3)
{
PrintEntry(phonebook);
}
if (iSelection == 4)
{
SearchForNumber(phonebook);

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

}
if (iSelection == 5)
{
printf("\nYou have chosen to exit the Phonebook.\n");
getch();
}
} while (iSelection<= 4);
}
void AddEntry (phone * phonebook)
{
pWrite = fopen("phonebook_contacts.dat", "a");
if ( pWrite == NULL )
{
perror("The following error occurred ");
exit(EXIT_FAILURE);
}
else
{
counter++;
realloc(phonebook, sizeof(phone));
printf("\nFirst Name: ");
scanf("%s", phonebook[counter-1].FirstName);
printf("Last Name: ");
scanf("%s", phonebook[counter-1].LastName);
printf("Phone Number (XXX-XXX-XXXX): ");
scanf("%s", phonebook[counter-1].PhoneNumber);
printf("\n\tFriend successfully added to Phonebook\n");

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

fprintf(pWrite, "%s\t%s\t%s\n", phonebook[counter-1].FirstName,


phonebook[counter-1].LastName, phonebook[counter-1].PhoneNumber);
fclose(pWrite);
}
}
void DeleteEntry (phone * phonebook)
{
int x = 0;
int i = 0;
char deleteFirstName[20]; //
char deleteLastName[20];
printf("\nFirst name: ");
scanf("%s", deleteFirstName);
printf("Last name: ");
scanf("%s", deleteLastName);
for (x = 0; x < counter; x++)
{
if (strcmp(deleteFirstName, phonebook[x].FirstName) == 0)
{
if (strcmp(deleteLastName, phonebook[x].LastName) == 0)
{
for ( i = x; i < counter - 1; i++ )
{
strcpy(phonebook[i].FirstName, phonebook[i+1].FirstName);
strcpy(phonebook[i].LastName, phonebook[i+1].LastName);
strcpy(phonebook[i].PhoneNumber, phonebook[i+1].PhoneNumber);
}
printf("Record deleted from the phonebook.\n\n");

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

--counter;
return;
}
}
}
printf("That contact was not found, please try again.");
}
void PrintEntry (phone * phonebook)
{
int x = 0;
printf("\nPhonebook Entries:\n\n ");
pRead = fopen("phonebook_contacts.dat", "r");
if (pRead == NULL)
{
perror("The following error occurred: ");
exit(EXIT_FAILURE);
}
else
{
for( x = 0; x < counter; x++)
{
printf("\n(%d)\n", x+1);
printf("Name: %s %s\n", phonebook[x].FirstName, phonebook[x].LastName);
printf("Number: %s\n", phonebook[x].PhoneNumber);
}
}
fclose(pRead);

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

}
void SearchForNumber (phone * phonebook)
{
int x = 0;
char TempFirstName[20];
char TempLastName[20];
printf("\nPlease type the name of the friend you wish to find a number for.");
printf("\n\nFirst Name: ");
scanf("%s", TempFirstName);
printf("Last Name: ");
scanf("%s", TempLastName);
for (x = 0; x < counter; x++)
{
if (strcmp(TempFirstName, phonebook[x].FirstName) == 0)
{
if (strcmp(TempLastName, phonebook[x].LastName) == 0)
{
printf("\n%s %s's phone number is %s\n", phonebook[x].FirstName,
phonebook[x].LastName, phonebook[x].PhoneNumber);
}
}
}
}

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

OUTPUT:

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

/*Account Holder balance maintenance using sequential access file*/


#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];
int main()
{
int ch;
clrscr();
do
{
printf("\n *******************");
printf("\n BANKING");
printf("\n ***********");
printf("\n 1.Create new account");
printf("\n 2.cash deposit");
printf("\n 3.cash withdraw");

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

printf("\n 4.low balance enquiry");


printf("\n 5.exit");
printf("\n Enter your choice:");
scanf("\n %d",&ch);
switch(ch)
{
case 1: creation();
break;
case 2: deposit();
break;
case 3: withdraw();
break;
case 4: lowbal();
break;
case 5:
break;
default:printf("Choice a valid option!!");
}
}
while(ch!=5);
}
void creation()
{
printf("\n ********************");
printf("\n NEW ACCOUNT CREATION");
printf("\n ********************");
printf("\n your account number is: %d",i);

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

s[a].no=i;
printf("\n Enter your name:");
scanf("%s",s[a].name);
printf("\n your deposit is minimum Rs.500");
s[a].dep=500;
a++;i++;
}
void deposit()
{
int no,b=0,m=0;float aa;
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);

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

s[m].dep+=aa;
printf("\n The balance in account is :%f",s[m].dep);
}
else
{
printf("\n Account Number is Invalid");
}
}
void withdraw()
{
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);

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

printf("\n Withdraw amount:");


scanf("%f",&aa);
if(s[m].dep<aa+500)
{
printf("\n Cannot Withdraw your accoumt has minimum balance");
}
else
{
s[m].dep=aa;
printf("\n The balance amount in account is :%f",s[m].dep);
}
}
else
printf("Invalid");
}
void lowbal()
{
int no,b=0;
float aa;
printf("\n ****************");
printf("\n Fllowing Account Holder's Balance<1000");
printf("\n ****************");
for(b=0;b<a;b++)
{
if(s[b].dep< 1000)
{
printf("\n\n Account number:%d",s[b].no);printf("\n Name:%s",s[b].name);}}}

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

OUTPUT:

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

/* Railway Ticket Reservation */


#include<stdio.h>
#include<conio.h>
int first=5,second=5,thired=5;
struct node
{
int ticketno;
int phoneno;
char name[100];
char address[100];
}s[15];
int i=0;
void booking()
{
printf("enter your details");
printf("\nname:");
scanf("%s",s[i].name);
printf("\nphonenumber:");
scanf("%d",&s[i].phoneno);
printf("\naddress:");
scanf("%s",s[i].address);
printf("\nticketnumber only 1-10:");
scanf("%d",&s[i].ticketno);
i++;
}
void availability()
{

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

int c;
printf("availability cheking");
printf("\n1.first class\n2.second class\n3.thired class\n");
printf("enter the option");
scanf("%d",&c);
switch(c)
{
case 1:if(first>0)
{
printf("seat available\n");
first--;
}
else
{
printf("seat not available");
}
break;
case 2: if(second>0)
{
printf("seat available\n");
second--;
}
else
{
printf("seat not available");
}
break;

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

case 3:if(thired>0)
{
printf("seat available\n");
thired--;
}
else
{
printf("seat not available");
}
break;
default:
break;
}
}
void cancel()
{
int c;
printf("cancel\n");
printf("which class you want to cancel");
printf("\n1.first class\n2.second class\n3.thired class\n");
printf("enter the option");
scanf("%d",c);
switch(c)
{
case 1:
first++;
break;

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

case 2:
second++;
break;
case 3:
thired++;
break;
default:
break;
}
printf("ticket is canceled");
}
void chart()
{
int c;
for(c=0;c<i;c++)
{
printf("\n Ticket No\t Name");
printf("%d\t%s\n",s[c].ticketno,s[c].name);
}
}
main()
{
int n;
clrscr();
printf("welcome to railway ticket reservation\n");
while(1) {
printf("1.booking\n2.availability cheking\n3.cancel\n4.Chart \n5. Exit\nenter
your option:");

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

scanf("%d",&n);
switch(n)
{
case 1: booking();
break;
case 2: availability();
break;
case 3: cancel();
break;
case 4:
chart();
break;
case 5:
printf("\n Thank you visit again!");
getch();
exit(0);
default:
break;
}
}
getch();
}

CS8261 C Programming Laboratory


NAME REGISTER NUMBER

OUTPUT:

CS8261 C Programming Laboratory

You might also like