1.
SUM OF TWO NUMBERS
#include<stdio.h>
void main()
{
inta,b,sum=0;
printf("Enter two numbers");
scanf("%d%d",&a,&b);
sum=a+b; printf("\nSum=
%d",sum);
}
Input and Output:
Enter two numbers : 10 20
Sum=30
1
2.CHECKING A NUMBER IS ODD OR EVEN
#include<stdio.h>
void main()
{
int a;
printf("Enter a number");
scanf("%d",&a); if(a
%2==0)
printf("%d is even",a);
else
printf("%d is odd",a);
}
Input and Output:
Enter a number:4
4 is even
3.LEAP YEAR OR NOT
#include<stdio.h>
void main()
{
int year;
printf("Enter the year");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
printf("\nThe Given year %d is a leap year");
else
printf("\nThe Given year %d is not a leap year");
}
Input and output:
Enter the year2000
The Given year 2000 is a leap year
4.SIMPLE CALCULATOR
#include<stdio.h>
void main()
{
int choice,a,b,c,d;
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
printf("\nYour choices:");
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n5.Sqaure");
printf("\n Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
c=a+b; printf("\nSum=
%d",c); break;
case 2:
c=a-b; printf("\nDifference=
%d",c); break;
case 3:
c=a*b; printf("\nProduct=
%d",c); break;
case 4:
c=a/b; printf("\nQuotient:
%d",c);
break;
case 5:
c=a*a;
d=b*b;
printf("\n Square of %d =%d",a,c);
printf("\n Square of %d =%d",b,d);
break;
default:printf("\nEnter your choice from 1 to 5");
}
}
Input and Output:
Enter two numbers:12 4
Your choices:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
Enter your choice:1
Sum=16
5.CHECKING A NUMBER IS ARMSTRONG OR NOT
#include<stdio.h>
void main()
{
int a,r,n,rem,sum=0;
printf("Enter the number:");
scanf("%d",&n);
a=n;
while(n!=0)
{
r=n%10;
sum+=r*r*r;
n=n/10;
}
if(a==sum)
{
printf("\n The number is an armstrong number");
}
else
{
printf("\n The number is not an armstrong number");
}
}
OUTPUT
Enter the number:371
The number is an armstrong number
6.SUM OF WEIGHTS BASED ON CONDITIONS
#include <stdio.h>
#include<math.h>
void main()
{
int a[15],w[15],i,j,t,n;
printf("Enter the number of elements");
scanf("%d",&n);
printf("Enter the elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
w[i]=getweight(a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(w[i]>w[j])
{
t=w[i];
w[i]=w[j];
w[j]=t;
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i<n;i++)
{
printf("<%d,%d>",a[i],w[i]);
}
}
int getweight(int n)
{
int w=0,c=0,i,root;
root=round(pow(n,1.0/3.0));
if(root*root*root==n)
w+=5;
if(n%4==0&&n%6==0)
w+=4;
for(i=1;i<=n;i++)
{
if(n%i==0)
c+=1;
}
if(c==2)
w+=3;
return w;
}
Input and output:
Enter the number of elements6
Enter the elements10
36
54
89
12
27
<10,0><54,0><89,3><36,4><12,4><27,5>
7. FINDING AVERAGE HEIGHT USING ARRAYS
#include <stdio.h>
int main()
{
inti,n,sum=0,count=0,height[100];
float avg;
printf("Enter the Number of Persons : ");
scanf("%d",&n);
printf("\nEnter the Height of each person in centimeter\n");
for(i=0;i<n;i++)
{
scanf("%d",&height[i]);
sum = sum + height[i];
}
avg = (float)sum/n;
//Counting
for(i=0;i<n;i++)
if(height[i]>avg)
count++;
//display
printf("\nAverage Height of %d persons is : %.2f\n",n,avg);
printf("\nThe number of persons above average : %d ",count);
}
Input and output:
Number of Person : 5
Persons Heights are : 150 155 162 158 154
Average Height is : 155.8
Number of persons above average : 2
8.TO FIND A BODY MASS INDEX USING 2-D ARRAY:
#include<stdio.h>
void main()
{
int s[50][2],bmi[50],i,n;
float h;
printf("Enter the number of students:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\nEnter the height(cm) and weight(kg):");
scanf("%d%d",&s[i][0],&s[i][1]); h=(float)(s[i]
[0]/100.0);
bmi[i]=(float)s[i][1]/(float)(h*h);
}
printf("\nStudent no:\tHeight\tWeight\tBMI\t Result\n");
for(i=1;i<=n;i++)
{
printf("\n%d\t\t%d\t%d\t%d\t",i,s[i][0],s[i][1],bmi[i]);
if(bmi[i]<15)
printf("Starvation\n");
else if(bmi[i]>14&&bmi[i]<18)
printf("Underweight\n");
else if(bmi[i]>17&&bmi[i]<26)
printf("Healthy\n");
else if(bmi[i]>25&&bmi[i]<31)
printf("Over weight\n");
else if(bmi[i]>30&&bmi[i]<36)
printf("Obese\n");
else
printf("Severe Obese\n");
}
}
Input and Output:
Enter the number of students:2
Enter the height(cm) and weight(kg):170 70
Enter the height(cm) and weight(kg):190 90
Student no: Height Weight BMI Result
1 170 70 24 Healthy
2 190 90 24 Healthy
9.REVERSE OF A GIVEN STRING
#include<stdio.h>
#include<string.h>
void main()
{
char a[50],t;
int l,r;
printf("Enter the string");
gets(a);
l=0;
r=strlen(a)-1;
while(l<r)
{
if(!isalpha(a[l]))
l++;
else if(!isalpha(a[r]))
r--;
else
{
t=a[l];
a[l]=a[r];
a[r]=t; l+
+;
r--;
}
}
printf(“The Reversed string is ..”);
puts(a);
Input and Output:
a$bcd./fg||
The Reversed string is…
g$fdc./ba||
10.NUMBER CONVERSION
(i) Decimal to Hexa decimal
#include<stdio.h>
#
include<math.h>
void main()
{
int a,
i=0,rem,j;
char hex[50];
printf("enter the number");
scanf("%d",&a); while(a!
=0)
{
rem=a%16;
if(rem<10) hex[i+
+]=rem+48; else
hex[i++]=rem+55;
a=a/16;
}
for(j=i-1;j>=0;j--)
printf("%c",hex[j]);
}
Input and Output:
Enter the number : 10
The Hexa value : A
(ii) Decimal to
Octal #
include<math.h>
#include<stdio.h>
void main()
{
int num,rem,oct=0,i=0;
printf("Enter a number:");
scanf("%d",&num);
while(num>0)
{
rem=num%8;
oct+=rem*pow(10,i);
num/=8;
i++;
}
printf("Octal=%d",oct);
}
Input and Output:
Enter the number : 10
The Octal value : 12
(iii) Decimal to Binary
#include<stdio.h>
void main()
{
int num,i,bin=0,rem;
printf("Enter the number");
scanf("%d",&num);
i=0;
while(num!=0)
{
rem=num%2;
bin=bin+rem*pow(10,i);
num=num/2;
i++;
}
printf("Binary = %d",bin);
}
Input and output:
Enter the number10
Binary = 1010
11.STRING HANDLING FUNCTIONS
(a)Find the total no of words
#include<stdio.h>
void main()
{
int i=0,wc=0;
char a[50];
printf("Enter a string:");
gets(a);
while(a[i]!='\0')
{
if(a[i]==' ')
wc++; i+
+;
}
printf("\nNo.of words=%d",wc+1);
}
Input and Output:
Enter a String: This is sample c program
No of Words=5
(b)Capitalize the first word of each sentence
#include<stdio.h>
void main()
{
int i=0,wc=0;
char a[50];
printf("Enter a string:");
gets(a);
i=0;
if(a[i]>='a' && a[i]<='z')
{
a[i]=a[i]-32;
i++;
}
while(a[i]!='\0')
{
if(a[i]=='.')
{
if(a[i+1]>='a' && a[i+1]<='z')
a[i+1]=a[i+1]-32;
}
i++;
}
printf("\nCapitalised string :");
puts(a);
}Input:
Enter a string
C is a Structured programming language.in c pointer concept is there.
OUTPUT:
Capitalised string:
C is a Structured programming language.In c pointer concept is there.
(c) Replace given word with another word:
#include<string.h>
#include<stdio.h>
void main()
{
int w,p,i=0,j=0,k;
char str[50][50],a[50],b[50],c[50];
printf("Enter the string");
gets(a);
printf("\nEnter the string to replace:");
scanf("%s",b);
printf("\nEnter the replacement word:");
scanf("%s",c);
p=strlen(a);
for(k=0;k<p;k++)
{
if(a[k]!=' ')
{
str[i][j]=a[k];
j++;
}
else
{
str[i][j]='\0';
j=0;
i++;
}
}
str[i][j]='\0';
w=i;
for(i=0;i<=w;i++)
{
if(strcmp(str[i],b)==0)
strcpy(str[i],c);
printf("%s ",str[i]);
}
}
Input :
Enter the string: This is Java Program
Enter the string to replace: Java
Enter the replacement word: Python
Output:
This is python Program
12.TOWERS OF HANOI USING RECURSION
#include<stdio.h>
void Hanoi(int n, char Beg, char Aux, char End)
{
if (n==1)
{
printf("\nMove disk 1 from %c to %c", Beg, End);
}
else
{
Hanoi ( n-1, Beg, End, Aux);
printf("\nMove disk %d from %c to %c", n, Beg, End);
Hanoi (n-1, Aux, Beg, End);
}
}
void main()
{
int n;
printf("Enter the number of disks:");
scanf("%d", &n);
Hanoi(n, 'A', 'B', 'C');
}
Input and Output:
Enter the number of disks : 3
Move disk 1 from A to C
Move disk 2 from A to B
Move disk 1 from C to B
Move disk 3 from A to C
Move disk 1 from B to A
Move disk 2 from B to C
Move disk 1 from A to C
13. SORT THE LIST OF NUMBERS USING PASS BY REFERENCE
#include<stdio.h>
void main()
{
int i,n;
int ar[10];
printf("Enter the number of elements\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the element:");
scanf("%d",&ar[i]);
}
printf("Unsorted list:\n");
for(i=0;i<n;i++)
printf("%d\t",ar[i]);
sort(n,&ar);
printf("\nReorder list is:\n");
for(i=0;i<n;i++)
printf("%d\t",ar[i]);
}
void sort(int m,int*x)
{
int i,j,t;
for(i=0;i<m-1;i++)
{
for(j=i+1;j<m;j++)
{
if(x[i]>x[j])
{
t=x[j];
x[j]=x[i];
x[i]=t;
}
}
}
}
Input and output:
Enter the number of elements
5
Enter the element:8
Enter the element:5
Enter the element:6
Enter the element:-2
Enter the element:7
Unsorted list:
8 5 6 -2 7
Reorder list is:
-2 5 6 7 8
EX.NO: 14 C PROGRAM TO GENERATE SALARY SLIP OF EMPLOYEES
USING STRUCTURES AND POINTERS
#include<stdio.h>
struct Employee
{
int empno ;
char name[10] ;
int bpay, da, hra, npay, gpay, pf;
} emp[10] ;
void main()
{
int i, n ;
struct Employee *ptr = emp;
printf("Enter the number of employees : ") ;
scanf("%d", &n) ;
for(i = 0 ; i < n ; i++)
{
printf("\n Enter the employee number : ") ;
scanf("%d", &ptr->empno) ;
printf("\n Enter the name : ") ;
scanf("%s", ptr->name) ;
printf("\n Enter the basic pay") ;
scanf("%d", &ptr->bpay);
ptr->da=80* ptr->bpay / 100;
ptr->hra=20* ptr->bpay / 100;
ptr->pf= 10* ptr->bpay / 100;
ptr->gpay= ptr->bpay + ptr->da + ptr->hra;
ptr->npay = ptr->gpay - ptr->pf;
printf("\n emp. No. Name \t Bpay \t da \t hra \t pf \t gpay \t npay\n\n") ;
printf("%d \t %s \t %d \t %d \t %d \t %d \t %d\t %d\n", ptr->empno, ptr-
>name, ptr
->bpay, ptr->da, ptr->hra, ptr->pf, ptr->gpay , ptr->npay) ;
}
}
INPUT AND OUTPUT:
Enter the number of employees : 2
Enter the employee number : 1002
Enter the name :RAGUL
Enter the basic pay:15000
emp.No Nam Bpay da hra gpay npay
e
1002 RAGUL 15000 12000 3000 30000 28500
Enter the employee number : 1005
Enter the name :MANI
Enter the basic pay:16000
emp.No Name Bpay da hra gpay npay
1005 MANI 16000 12800 3200 32000 30400
Ex.No15: C PROGRAM TO COMPUTE INTERNAL MARKS OF
STUDENTS FOR FIVE DIFFERENT SUBJECTS USING
STRUCTURES AND FUNCTIONS
#include<stdio.h>
struct Student
{
char name[20];
int rollno;
int m1,m2,m3,m4,m5;
}stu[30];
void accept(struct Student stu[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\nEnter the student name: ");
scanf("%s",&stu[i].name);
printf("\nEnter the student rollno : ");
scanf("%d",&stu[i].rollno);
printf("\nEnter the mark of subject1 : ");
scanf("%d",&stu[i].m1);
printf("\nEnter the mark of subject2 : ");
scanf("%d",&stu[i].m2);
printf("\nEnter the mark of subject3 : ");
scanf("%d",&stu[i].m3);
printf("\nEnter the mark of subject4 : ");
scanf("%d",&stu[i].m4);
printf("\nEnter the mark of subject5 : ");
scanf("%d",&stu[i].m5);
}
}
void internal_marks(struct Student stu[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\nName : %s",stu[i].name);
printf("\nRollno: %d",stu[i].rollno);
printf("\nInternal Mark for subject1: %d",stu[i].m1*20/100);
printf("\nInternal Mark for subject2: %d",stu[i].m2*20/100);
printf("\nInternal Mark for subject3: %d",stu[i].m3*20/100);
printf("\nInternal Mark for subject4: %d",stu[i].m4*20/100);
printf("\nInternal Mark for subject4: %d",stu[i].m5*20/100);
}
}
void main()
{
int n;
printf("Enter the number of students:\n");
scanf("%d",&n);
accept(stu,n);
internal_marks(stu,n);
}
INPUT AND OUTPUT:
Enter the number of students:
2
Enter the student name: Kumar
Enter the student rollno: 603
Enter the mark of subject 1: 60
Enter the mark of subject 2: 100
Enter the mark of subject 3: 70
Enter the mark of subject 4: 90
Enter the mark of subject 5: 90
Enter the student name: Mohan
Enter the student rollno: 604
Enter the mark of subject 1: 75
Enter the mark of subject 2: 59
Enter the mark of subject 3: 66
Enter the mark of subject 4: 85
Enter the mark of subject 5: 60
Name: Kumar
Rollno: 603
Internal Mark for subject 1:10
Internal Mark for subject 2:20
Internal Mark for subject 3:14
Internal Mark for subject 4:18
Internal Mark for subject 5:18
Name: Mohan
Rollno: 604
Internal Mark for subject 1:15
Internal Mark for subject 2:11
Internal Mark for subject 3:13
Internal Mark for subject 4:17
Internal Mark for subject 5:10
EX.No: 16 INSERT, UPDATE, DELETE AND APPEND TELEPHONE
DETAILS OF AN INDIVIDUAL OR A COMPANY INTO A TELEPHONE
DIRECTORY USING RANDOM ACCESS FILE.
#include<stdio.h>
struct person
{
char name[20],no[20];
}p;
void insert()
{
FILE *fp;
int i;
fp=fopen("tel1.txt","w");
printf("Enter name: ");
scanf("%s",p.name);
printf("Enter phone number: ");
scanf("%s",p.no);
fwrite(&p,sizeof(p),1,fp);
fclose(fp);
}
void display()
{
FILE *fp;
int i;
fp=fopen("tel1.txt","rb");
rewind(fp);
while(fread(&p,sizeof(p),1,fp)==1)
{
printf("Name=%s",p.name);
printf("No=%s",p.no);
}
fclose(fp);
}
void append()
{
FILE *fp;
fp=fopen("tel1.txt","ab");
printf("Enter name: ");
scanf("%s",p.name);
printf("Enter no: ");
scanf("%s",p.no);
fwrite(&p,sizeof(p),1,fp);
fclose(fp);
}
void main()
{
int ch;
do
{
printf("1.insert\n 2.display\n 3.append\n 4.exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
display();
break;
case 3:
append();
break;
case 4:
exit(0);
}
}while(ch<=4);
}
INPUT AND OUTPUT:
1
Enter name: kala
Enter phone number: 585989
1.insert
2.display
3.append
4.exit
2
Name=kala No=585989
1.insert
2.display
3.append
4.exit
3
Enter name: kayal
Enter no: 787900
1.insert
2.display
3.append
4.exit
2
Name=kala No=585989
Name=kayal No=787900
1.insert
2.display
3.append
4.exit
17. COUNT THE NUMBER OF ACCOUNT HOLDERS WHOSE
BALANCE IS LESS THAN THE MINIMUM BALANCE USING
SEQUENTIAL ACCESS FILE
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define MINBAL 500
struct Bank_Account
{
char no[10];
char name[20];
char balance[15];
};
struct Bank_Account acc;
void main()
{
long int pos1,pos2,pos;
FILE *fp;
char ano[10],amt[10];
char choice;
int type,flag=0;
float bal;
do
{
fflush(stdin);
printf("1. Add a New Account Holder\n");
printf("2. Display\n");
printf("3. Deposit or Withdraw\n");
printf("4. Number of Account Holder Whose Balance is less than the Minimum
Balance\n");
printf("5. Stop\n");
printf("Enter your choice : ");
choice=getchar();
switch(choice)
{
case '1' :
fflush(stdin);
fp=fopen("acc.txt","a");
printf("\nEnter the Account Number : ");
gets(acc.no);
printf("\nEnter the Account Holder Name : ");
gets(acc.name);
printf("\nEnter the Initial Amount to deposit : ");
gets(acc.balance);
fseek(fp,0,2);
fwrite(&acc,sizeof(acc),1,fp);
fclose(fp);
break;
case '2' :
fp=fopen("acc.txt","r");
if(fp==NULL)
printf("\nFile is Empty");
else
{
printf("\nA/c Number\tA/c Holder Name Balance\n");
while(fread(&acc,sizeof(acc),1,fp)==1)
printf("%-10s\t\t%-20s\t%s\n",acc.no,acc.name,acc.balance);
fclose(fp);
}
break;
case '3' :
fflush(stdin);
flag=0;
fp=fopen("acc.txt","r+");
printf("\nEnter the Account Number : ");
gets(ano);
for(pos1=ftell(fp);fread(&acc,sizeof(acc),1,fp)==1;pos1=ftell(fp))
{
if(strcmp(acc.no,ano)==0)
{
printf("\nEnter the Type 1 for deposit & 2 for withdraw : ");
scanf("%d",&type);
printf("\nYour Current Balance is : %s",acc.balance);
printf("\nEnter the Amount to transact : ");
fflush(stdin);
gets(amt);
if(type==1)
bal = atof(acc.balance) + atof(amt);
else
{
bal = atof(acc.balance) - atof(amt);
if(bal<0)
{
printf("\nRs.%s Not available in your A/c\n",amt);
flag=2;
break;
}
}
flag++;
break;
}
}
if(flag==1)
{
pos2=ftell(fp);
pos = pos2-pos1;
fseek(fp,-pos,1);
sprintf(amt,"%.2f",bal);
strcpy(acc.balance,amt);
fwrite(&acc,sizeof(acc),1,fp);
}
else if(flag==0)
printf("\nA/c Number Not exits... Check it again");
fclose(fp);
break;
case '4' :
fp=fopen("acc.txt","r");
flag=0;
while(fread(&acc,sizeof(acc),1,fp)==1)
{
bal = atof(acc.balance);
if(bal<MINBAL)
flag++;
}
printf("\nThe Number of Account Holder whose Balance less than the Minimum Balance
:%d",flag);
fclose(fp);
break;
case '5' :
fclose(fp);
exit(0);
}
printf("\nPress any key to continue. ");
} while (choice!='5');
}
Input and output:
1. Add a New Account Holder
2. Display
3. Deposit or Withdraw
4. Number of Account Holder Whose Balance is less than the Minimum Balance
5. Stop
Enter your choice : 1
Enter the Account Number : 12
Enter the Account Holder Name :raji
Enter the Initial Amount to deposit : 2000
Press any key to continue....
1. Add a New Account Holder
2. Display
3. Deposit or Withdraw
4. Number of Account Holder Whose Balance is less than the MinimumBalance
5. Stop
Enter your choice : 2
A/c Number A/c Holder Name Balance
5202 kala 300
02 kala 9000.00
11 kala 2000
12 raji 4000.00
12 raji 2000
Press any key to continue....
1. Add a New Account Holder
2. Display
3. Deposit or Withdraw
4. Number of Account Holder Whose Balance is less than the Minimum Balance
5. Stop
Enter your choice : 3
Enter the Account Number : 12
Enter the Type 1 for deposit & 2 for withdraw : 1000
Your Current Balance is : 4000.00
Enter the Amount to transact : 2000
Press any key to continue....
EX.NO 18 RAILWAY RESERVATION SYSTEM
#include<stdio.h>
#include<string.h>
struct air
{
char name[20];
int age;
long phno;
char address[50];
int ticketno;
}
s[100];
void view();
void reserve();
void cancel();
void form();
void menu()
{
int ch;
printf("\n\t RAILWAY RESERVATION SYSTEM");
printf("\n \n 1.VIEW ALL TRAINS");
printf("\n \n 2.RESERVE A TICKET");
printf("\n \n 3.CANCEL A TICKET");
printf("\n \n 4.EXIT");
printf("\n Enter your choice:\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
view();
menu();
break;
case 2:
reserve();
menu();
break;
case 3:
cancel();
menu();
break;
case 4:
break;
default:
printf("\n Enter a valid choice");
}
}
void view()
{
printf("CODE-ROUTE-TIMINGS");
printf("\n 1021-Delhi to Mumbai-06:30");
printf("\n 1024-Delhi to Kolkata-06:30");
printf("\n 1098-Delhi to Amritsar-14:30");
printf("\n 1987-Delhi to Bengaluru-18:00");
printf("\n 1576-Delhi to Chennai-20:00\n");
}
void form()
{
int i,n;
printf("\n Enter the number of tickets: \t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter name: ");
scanf("%s",s[i].name);
printf("\n Enter age: ");
scanf("%d",&s[i].age);
printf("\n Enter phone number: ");
scanf("%ld",&s[i].phno);
printf("Enter address: ");
scanf("%s",s[i].address);
printf("\n Enter your security number code: ");
scanf("%d",&s[i].ticketno);
}
printf("Your ticket is confirmed");
}
void reserve()
{
int code, total_seats=100, reserved=0, class;
if(reserved<total_seats)
{
reserved++;
printf("Enter the train code: ");
scanf("%d",&code);
if(code==1021||code==1024||code==1098||code==1987||code==1576)
{
printf("\n 1.First class (fare Rs.1500)");
printf("\n 2.Second class (fare Rs.800)");
printf("\n 3.Sleeper class (fare Rs.500)\n");
scanf("%d",&class);
if(class==1)
{
printf("Your fare is Rs.1500\n");
form();
menu();
}
else if (class==2)
{
printf("\n Your fare is RS.800\n");
form();
menu();
}
else if(class==3)
{
printf("\n Your fare is Rs.500\n");
form();
menu();
}
else
{
printf("Enter valid choice(1,2 or 3)");
menu();
}
}
else
printf("WARNING! YOU HAVE ENTERED THE WRONG CODE");
}
}
void cancel()
{
int ticket;
char ch;
int i,n;
printf("\n Enter the number of tickets:\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the ticket number: ");
scanf("%d",&ticket);
if(ticket==s[i].ticketno)
{
printf("Your ticket is cancelled");
}
else
{
printf("Ticket number is invalid");
menu();
}
}
}
void main()
{
printf("\n WELCOME TO RAILWAY RESERVATION SYSTEM \n");
menu();
}
INPUT AND OUTPUT:
WELCOME TO RAILWAY RESERVATION SYSTEM
RAILWAY RESERVATION SYSTEM
1.VIEW ALL TRAINS
2.RESERVE A TICKET
3.CANCEL A TICKET
4.EXIT
Enter your choice: 1
CODE-ROUTE-TIMINGS
1021-Delhi to Mumbai-06:30
1024-Delhi to Kolkata-06:30
1098-Delhi to Amritsar-14:30
1987-Delhi to Bengaluru-18:00
1576-Delhi to Chennai-20:00
RAILWAY RESERVATION SYSTEM
1.VIEW ALL TRAINS
2.RESERVE A TICKET
3.CANCEL A TICKET
4.EXIT
Enter your choice: 2
Enter the train code: 1021
1.First class (fare Rs.1500)
2.Second class (fare Rs.800)
3.Sleeper class (fare Rs.500)
1
Your fare is Rs.1500
Enter the number of tickets: 1
Enter name: aa
Enter age: 14
Enter phone number: 2345
Enter address: xxx
Enter your security number code: 1021
Your ticket is confirmed
RAILWAY RESERVATION SYSTEM
1.VIEW ALL TRAINS
2.RESERVE A TICKET
3.CANCEL A TICKET
4.EXIT
Enter your choice: 3
Enter the number of tickets: 1
Enter the ticket number: 1021
Your ticket is cancelled
RAILWAY RESERVATION SYSTEM
1.VIEW ALL TRAINS
2.RESERVE A TICKET
3.CANCEL A TICKET
4.EXIT
Enter your choice: 4