c programming codes
TRANSCRIPT
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 1/30
C Programming Codes
http://schooling24.blogspot.com
XOR Magic Function
#define swap(x,y) (x^=y^=x^=y)
This magical single line can swap two number Do you want to know how it works just read
following
example code:
#include<stdio.!
#define swap(x,y) (x^=y^=x^=y)
"ain()
int a=$,%=&'
swap(a,%)'
pintf(*d *da,%)'
+
Output & $
Do you hert about XOR fonction here i am showing simple xor table for and !
-/01 O01/01
2 3 Result(2 XOR 3)
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 2/30
! !
! !
! !
-"p pop 4"are it is clear that when both input a and b are same output will be zero
l"p pop 5 XOR of any non zero and zero is always e#uals to that non zero number$char%
-"p pop $ 6 we use ^ symbol for make XOR of any to functions
if you understand ! and & properties ypu can easily understand 'agical function
(s you may be know
()*&+
,t gi-es (*()&+
hare ) is a operator now . is also a operator so
X.*/+ returns X*X./+
now look at 'acro
#define swap(x,y) (x^=y^=x^=y)
now on splitting it gi-es
!% x*x.y
&% y*y.x
0% x*x.y
for example let x=3 and y= 5 so x^y=6
pass zero
x=3 y=5
pass first x consist XOR of x any y
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 3/30
x=3^5 y=5
pass second y * y.x1hare x* x.y from pass !2 * y.x.y
x=3^5 y=5^3^5
from prop ! y.y *
x=3^5 y=3^(5^5)
As 5^5=0
y=3^0
from prop & x. * x
y=3
so y consists x
pass third x*x1hare x* x.y from pass !2.y1hare y*x from pass &2
x=3^5^3 y=3
x* x.y.x on using prop !
x=5^(3^3)
x=5^0
on using prop &
x=5
now x consists y
swapping done successful
poga""ing fo finding day fo" date
Program to find day when a date is gi-en
3include4stdio%h5main126
int d7m7y7i+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 4/30
int r*7r!*7r&*7s*+
input8
printf19:nter the D(T: 'O;T" and /:(R
92+scanf19<d <d <d97=d7=m7=y2+
if1m**&26 if11d5&>2==1y<?@*226
printf19
Aool7,n-alid date in Aebruary of non leap year%The maximum-alue is &>92+
goto input+
B if11d5&2==1y<?**226
printf19
Aool7,n-alid date in Aebruary of leap year%The maximum-alue is &92+ goto input+
B
B else if11m**!21m**021m**E21m**F21m**>21m**!21m**!&226
if1d50!26
printf19Aool7,n-alid date in <d th month%The maximum -alue is
0!97m2+
goto input+
B B
else if111m**?21m**G21m**21m**!!22==1d50226
printf19Aool7,n-alid date in the <d th month%The maximum -alue
is
097m2+ goto input+
B
else if11d50!226 printf19
:nter -alid date92+
goto input+B
if11d4!21m4!226
printf19Aool7:nter positi-e -alid data
92+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 5/30
goto input+
B
else 6
switch1m26case !8
case !8r!*d)&+
break+
case &8case 08
case !!8
r!*d)E+ break+
case ?8
case F8r!*d)!+ break+
case 8
case !&8r!*d+
break+
case E8r!*d)0+
break+
case G8
r!*d)G+ break+
case >8
r!*d)?+ break+
default8
6 printf19
DonHt I know that there is no month greater than !&%:nter
-alidmonth
Once again enter the Date 'onth /ear 92+
goto input+B
B
Bif1y4&026
for1i*&&+i5*y+iJJ26
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 6/30
if11i**y2==1i<?**226
if1m5&2 s*s)!+
else if1m4*&2 s*s)&+ break+
B
else if1i<?**26 if1i<!**26
if1i<?**2
s*s)&+ else s*s)!+
B
else s*s)&+ B
else s*s)!+
B r&*FJs<F+ B
else if1y5&026
for1i*&?+i4*y+i))26 if11i**y2==1i<?**226
if1m5&2 s*s)&+
else if1m4*&2 s*s)!+ break+
B
else if1i<?**26
if1i<!**26 if1i<?**2
s*s)&+
else s*s)!+ B
else s*s)&+
B else s*s)!+
B
r&*s<F+ B
else r&*+r*1r!)r&2<F+
printf1992+
switch1r26
case 8 printf19The Day is KI;D(/92+
break+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 7/30
case !8
printf19The Day is 'O;D(/92+
break+case &8
printf19The Day is TI:KD(/92+ break+
case 08 printf19The Day is L:D;:KD(/92+
break+
case ?8 printf19The Day is T"IRKD(/92+
break+
case E8 printf19The Day is AR,D(/92+
break+
case G8 printf19The Day is K(TIRD(/92+ break+
B
printf19Thanks for using my program
92+
B
loop poga""ing in c
!%
Programming for following output :
20 7 8 9 10
19 6 1 2 11 18 5 4 3 12 17 16 15 14 13
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 8/30
#include <tdio!"#include <conio!"#define ma$%a&'( %%a(<%'()%'(:%a((#define a'%a( %%a(0)%a(:*%a((
int foo%int $& int +(, int t - ma$%a'%$(& a'%+((. int u - t / t. int - u * 1. - / u.
if %$ -- *t( /- u / t * +. ele if %+ -- *t( /- 3 u / $ * t. ele if %+ -- t ( /- t * $. ele /- + * t. return .
int main%(, clrcr%(. int $& +. for %+-*1.+<-2.+//( , for %$-*2.$<-2.$//( printf%5d& foo%$& +((. printf%n(. getc"%(.
/on%oo7 in 6
$MNy (nkit DhirM$
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 9/30
3include4conio%h5
3include4stdio%h5
3include4stdlib%h53include4graphics%h5
3include4ctype%h53include4string%h5
3define '(XDN E
$Mloble KectionM$
int i*+
long int phone'(XDN)!Q+
int room'(XDN)!Q+int roomtemp'(XDN)!Q+
long int phonetemp'(XDN)!Q+
-oid (dd:ntry1int7long int2+int addcount*+
int currenteadd+
int Delete:ntry1int7long int2+
int AindPhone1long int2+int AindRoom1int2+
int phonefound7roomfound+
int delentry+int totdelentry*+
int Sist(ll1-oid2+
int Khort(ll:ntries1char2+
int etTotal:ntries1-oid2+int chkstrdig1char strQ7int range2+
char menu1-oid2+
-oid SoadDN1-oid2+-oid exitmenu1-oid2+
-oid drawscreen1-oid2+
-oid refreshscreen1-oid2+
char dbload>Q+
$M'ain AuctionM$
-oid main1-oid2
6
char iroom>Q7iphone>Q7add#uit+ char option7sortopt7exitopt+
int phonecheck7roomcheck7deletecheck7sortcheck7listcheck+
int iroomsearch7iroomdel+ int intiroom7totalentries+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 10/30
int erroriphone7erroriroom+
long int iphonesearch7iphonedel7longintiphone+
strcpy1dbload79;o database file loaded 1R(' 'OD:@2%92+
do6
do
6 option*menu12+
if 1option ** H!H2
6
currenteadd*+ for 1i*addcount+i4'(XDN+i))2
6
clrscr12+
refreshscreen12+ drawscreen12+
gotoxy1!7?2+ printf1955 (dd entry 4492+
gotoxy1!7&E2+
cprintf19Please (dd /our :ntry7lea-e blank to #uit to 'ain 'enu92+ gotoxy1!7G2+
printf19:nter Room ;umber<0dQ8 97i)!2+
gets1iroom2+
if 1iroomQ**HH2 6
gotoxy1!7&E2+ cprintf19/ou choose to #uit8 :ntry <d was not added to the database%97i)!2+ getch12+
break+
B printf19:nter Phone ;o% <0dQ 897i)!2+
gets1iphone2+
if1iphoneQ**HH2
6 gotoxy1!7&E2+
cprintf19/ou chose to #uit8 :ntery <d was not added to database%97i)!2+
getch12+ break+
B
erroriroom*chkstrdig1iroom7?2+ erroriphone*chkstrdig1iphone7>2+
while1erroriroom@*2
6
if1erroriroom**J!2
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 11/30
6
clrscr12+
refreshscreen12+ drawscreen12+
gotoxy1!7?2+ printf1955(dd :ntry4492+
gotoxy1!7&E2+ cprintf19:rror8Room ;umberJout of range7your entry was greater then ? digits%92+
gotoxy1!7?2+
printf19Re :nter Room ;umber<0dQ897i)!2+ gets1iroom2+
B
if1erroriroom**J&2 6
clrscr12+
refreshscreen12+ drawscreen12+ gotoxy1!7?2+
printf19MMM (dd :ntry MMM92+
gotoxy1!7&E2+ cprintf19:rror8Room ;umberJCharacter1s2 detected7character1s2 are not allowed%92+
gotoxy1!7?2+
printf19Re :nter Room ;umber<0dQ897i)!2+ gets1iroom2+
B
erroriroom*chkstrdig1iroom7?2+
B while 1erroriphone@*2
6
if1erroriphone**J!2 6
clrscr12+
refreshscreen12+ drawscreen12+
gotoxy1!7?2+
printf1955(dd :ntry4492+ gotoxy1!7&E2+
cprintf19:rror8Phone ;umber Jout of range7your entry was greater then > digits%92+ gotoxy1!7G2+
printf19Room ;umber<0dQ :ntry897i)!2+ gets1iphone2+
B
if1erroriroom**J&2 6
clrscr12+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 12/30
refreshscreen12+
drawscreen12+
gotoxy1!7?2+ printf1955 (dd :ntry 4492+
gotoxy1!7&E2+ cprintf19:rror8Phone ;umberJCharacter1s2 detected7character1s2 are not allowed%92+
gotoxy1!7G2+ printf19Room ;umber<0dQ897i)!2+
gotoxy1!7F2+
printf19Re :nter Room ;umber<0dQ897i)!2+ gets1iphone2+
B
erroriphone*chkstrdig1iphone7>2+ B
if 1erroriphone** == erroriroom**2
6 intiroom*atoi1iroom2+ longintiphone*atol1iphone2+
currenteadd))+
(dd:ntry1intiroom7longintiphone2+ B
B
if1addcount**'(XDN2 6
gotoxy1!7&E2+
cprintf19aDatabase is full@8<d entries were added7that is the max% no% that i can
hold97addcount2+ getch12+
B
B else if 1option ** H&H2
6
delentry*+ clrscr12+
refreshscreen12+
drawscreen12+ gotoxy1!7?2+
printf1955 Delte :ntry 4492+ gotoxy1!7G2+
printf19:nter Room ;umber to delete892+ scanf19<ld97=iphonedel2+
flushall12+
deletecheck*Delete:ntry1iroomdel7iphonedel2+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 13/30
if1deletecheck**2
6
gotoxy1!7&E2+ cprintf19Kuccessful 8 Ther ars <d :ntries in database797addcount2+
cprintf19delete <d%97delentry2+ getch12+
B if1deletecheck**J!2
6
gotoxy1!7&E2+ cprintf19:rror8 Room ;o%$Phone ;o% /our looking not found92+
getch12+
B B
else if1option**H0H2
6 phonefound*+ clrscr12+
refreshscreen12+
drawscreen12+ gotoxy1!7?2+
printf1955 Aind Room ;umber 4492+
gotoxy1!7G2+ printf19:nter Phone number to search for 892+
scanf19<ld97=iphonesearch2+
phonecheck * AindPhone1iphonesearch2+
if 1phonecheck**2 6
gotoxy1!7&E2+
cprintf19Kuccessful8There are currently <d entries in the database797addcount2+ printf19found <d%97phonefound2+
getch12+
B
if1phonecheck**J!2 6
gotoxy1!7&E2+
cprintf19:rror8The Phone ;o% /ou looking for not found%92+ getch12+
B
B
else if1option**H?H2 6
roomfound*+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 14/30
clrscr12+
refreshscreen12+
drawscreen12+ gotoxy1!7?2+
printf1955 Aind Phone ;umber 4492+ gotoxy1!7G2+
printf19:nter room number to search for 892+ scanf19<d97=iroomsearch2+
roomcheck * AindRoom1iroomsearch2+
if 1roomcheck**2
6 gotoxy1!7&E2+
cprintf19Kuccessful8There are currently <d entries in the database797addcount2+
cprintf19found <d%97roomfound2+
getch12+ B
if1phonecheck**J!2 6
gotoxy1!7&E2+
cprintf19:rror8The Room ;o% /ou looking for not found%92+ getch12+
B
B
else if 1option**HEH2 6
clrscr12+ refreshscreen12+ drawscreen12+
gotoxy1!7?2+
printf1955 Sist (ll 44nn92+ listcheck*Sist(ll12+
if1listcheck**2
6
gotoxy1!7&E2+ cprintf19Sist Kuccessful92+
getch12+
B if 1listcheck**J!2
6
gotoxy1!7&E2+ cprintf19:npty Sist92+
getch12+
B
B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 15/30
else if1option**HGH2
6
totalentries * eTotal:ntries12+ gotoxy1!7&E2+
cprintf19Ther are <d :ntries stored in the database%97totalentries2+ getch12+
B else if 1option**HFH2
6
clrscr12+ refreshscreen12+
drawscreen12+
gotoxy1!7?2+ printf19Press H(H to sort database in(Qscending order92+
gotoxy1!7F2+
printf19Press HDH to sort database inDQescending order92+ gotoxy1!72+ printf19;ote 8 DataNase is Korted by phone no% entries%92+
sortopt*getch12+
flushall12+
sortcheck * Kort(ll:ntries1sortopt2+
getch12+
if1sortcheck**2
6
gotoxy1!7&E2+ cprintf19Database was successfully sorted%92+
getch12+
B if1sortcheck**J!2
6
gotoxy1!7&E2+ cprintf19Database was not sorted% J Database is empty@92+
getch12+
B B
else if1option**H>H2 6 clrscr12+
refreshscreen12+
drawscreen12+
gotoxy1!7?2+ printf1955 Soad Database 4492+
SoadDN12+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 16/30
B
else if1option**HH2
6 gotoxy1!7&E2+
cprintf19Do /ou really want to exitU Press H/H to conform7 anykey to cancel92+ exitopt*getch12+
flushall12+ if1exitopt**HyH exitopt**H/H2
6
clrscr12+ refreshscreen12+
drawscreen12+
gotoxy1!7?2+ printf1955 :xit To ystem 44nn92+
exitmenu12+
B B else
6
cprintf19:rror8 ,n-alid option@ Kelect an option between ! to 92+ getch12+
flushall12+
B Bwhile 1option 5HH option 4 H!H2+
Bwhile 1option @* HVH2+
B
$M
Auctions DefinationM$
-oid (dd:ntry1int r7long int p2
6 roomiQ*r+
phoneiQ*p+
addcount))+ printf19nRoom ;o% <J?dQnPhone ;o%<J>ldQn<d entries added%97r7p7currenteadd2+
getch12+B
int Delete:ntry1int r7long int p26
int k7x7delfoundflag*J!7loopmo-7loopmo-stop7countdel*+
char delme+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 17/30
for1k*+k4addcount+k))2
6
if1addcount@*2 6
if1r**roomkQ == p ** phonekQ2 6
gotoxy1!7>2+ printf19'atch Aound8 n Room ;o% <J?dQtPhone ;o% <J>dQ was found in record ;o%
<0dQn97roomkQ7phonekQ7k)!2+
delme*getch12+ flushall12+
if1delme**HyHdelme**H/H2
6 roomtemptotdelentryQ*roomkQ+
roomkQ*J!+
phonetemptotdelentryQ*phonekQ+ phonekQ*J!+ delentry))+
totdelentry))+
B B
B
B if 1addcount@*2
6
for1x*+x4delentry+x))2
6 for1k*+k4addcount+k))2
6
if1roomkQ**J! == phonekQ**J!2 6
loopmo-stop*+
loopmo-*+ countdel))+
loopmo-stop*addcountJ1k)!2+
while1loopmo-stop @* loopmo-2 6
roomk)loopmo-Q*room1k)!2)loopmo-Q+ phonek)loopmo-Q*phone1k)!2)loopmo-Q+
loopmo-))+ B
B
B B
B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 18/30
addcount*addcountJdelentry+
if1delfoundflag**2
6 return12+
B else
6 return1J!2+
B
B
int AindPhone1long int p26
int k7phonefoundflag*J!+
gotoxy1!7>2+
for1k*+k4addcount+k))2 6
if1addcount@*2 6
if1k@* == 1k<!E2**2
6 gotoxy1!7>2+
getch12+
B
if1p**phonekQ2 6
printf19Phone ;o% <J>ldQ was found in record no7 <0dQtRoom ;o% <J?dQn97phonekQ7k)!7roomkQ2+ phonefound))+
phonefoundflag*+
B B
B
if 1phonefoundflag **2
6 return12+
B
else 6
return1J!2+
BB
int AindRoom1int p2
6
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 19/30
int k7roomfoundflag*J!+
gotoxy1!7>2+
for1k*+k4addcount+k))2 6
if1addcount@*2 6
if1k@* == 1k<!E2**2 6
gotoxy1!7>2+
getch12+ B
if1p**roomkQ2
6 printf19Room ;o% <J?dQ was found in record no7 <0dQtPhone ;o% <J
>ldQn97roomkQ7k)!7phonekQ2+
roomfound))+ roomfoundflag*+ B
B
B if 1roomfoundflag **2
6
return12+ B
else
6
return1J!2+ B
B
int Sist(ll1-oid26
int k+
gotoxy1!7G2+
for1k*+k4addcount+k))2 6
if1k@*==1k<!F2**2
6 gotoxy1!7G2+
getch12+
B if1roomkQ@*J! == phonekQ @*J!2
6
printf19Room ;o% <0dQ 8<J?dtPhone ;o% <0dQ 8<J>ldn97k)!7roomkQ7k)!7phonekQ2+
B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 20/30
B
if 1addcount**2
6 return1J!2+
B else
6 return12+
B
B
int eTotal:ntries1-oid26
return1addcount2+
B
int Kort(ll:ntries1char sel2
6
int k7roomstrtmp7sortalldone+
long int phonestrtmp+ if1addcount@*2
6
do 6
sortalldone*+
for1k*+k4addcount+k))2
6 if11phonekQ5phonek)!Q2 == 1sel ** HaH sel ** H(H2 == 1k@*addcountJ!22
6
phonestrtmp*phonekQ+ phonekQ*phonek)!Q+
phonek)!Q*phonestrtmp+
roomstrtmp*roomkQ+ roomkQ*roomk)!Q+
roomk)!Q*roomstrtmp+
sortalldone*!+ B
if11phonekQ4phonek)!Q2 == 1sel ** HdH sel ** HDH2 == 1k@*addcountJ!22 6 phonestrtmp*phonekQ+
phonekQ*phonek)!Q+
phonek)!Q*phonestrtmp+
roomstrtmp*roomkQ+ roomkQ*roomk)!Q+
roomk)!Q*roomstrtmp+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 21/30
sortalldone*!+
B
B Bwhile 1sortalldone2+
B if11sel**HaHsel**H(H2 == addcount@*2
6 gotoxy1!7&E2+
printf19/ou ha-e chosen to sort the database in (Qscending order%92+
return12+ B
else if11sel**HdHsel**HDH2 == addcount@*2
6 gotoxy1!7&E2+
printf19/ou ha-e chosen to sort the database in DQecending order%92+
return12+ B else if11sel**HaHsel**H(Hsel**HdHsel**HDH2 == addcount@*2
6
gotoxy1!7!&2+ printf19,n-alid option J database was not storeed92+
B
else return1J!2+
B
int chkstrdig1char strQ7int range26 int length*7k+
length*strlen1str2+
if1length5range2 6
return1J!2+
B
if1length4*range2 6
for1k*+k4length+k))2
6 if1isdigit1strkQ2**2
6
return1J&2+ B
B
return12+
B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 22/30
B
-oid SoadDN1-oid2
6
int count7nofilen7dbfilecount*+ char finphone>Q+
char finroom>Q+
int errorjunk+ long int ifinphone+
int ifinroom+
A,S: Mf!+
gotoxy1!7G2+ printf19:nter the filename of database 892+
gotoxy1!7F2+
printf19(s 8 c8mydata%txt92+ gotoxy10F7G2+
gets1dbload2+
flushall12+
f! * fopen1dbload79r92+ if 1f!**;ISS2
6
gotoxy1!7&E2+ fprintf1stderr79There was an error reading your database file@92+
strcpy1dbload79;o database file loaded1R(' 'OD:@2%92+
getch12+
exit+ B
else
6 for 1count*+count4'(XDN+count))2
6
if1@feof1f!22 6
fscanf1f!79<st<sn97=finroom7=finphone2+
errorjunk*chkstrdig1finroom7?2+ errorjunk*chkstrdig1finroom7>2+
if1errorjunk**J!errorjunk**J&2 6 printf19Korry this was an in-alid databasen;ow Lorking in R(; 'OD:@92+
getch12+
strcpy1dbload79;o database file loaded 1R(' 'OD:@2%92+
break+ B
ifinroom*atoi1finroom2+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 23/30
ifinphone*atol1finphone2+
roomcountQ*ifinroom+
phonecountQ*ifinphone+ dbfilecount))+
B B
if1errorjunk**2 6
gotoxy1!7&E2+
printf19Database <s7 was successfully loaded@97dbload2+ getch12+
addcount*dbfilecount+
B B
fclose1f!2+
B
char menu1-oid26
char optrtn+
clrscr12+ window1!7!7>7&E2+
textcolor1/:SSOL2+
textbackground1NS(CW2+
refreshscreen12+ drawscreen12+
gotoxy1!7?2+ printf19!Q J (dd entryn&Q J Delete entryn
0Q J Aind room ;umbern
?Q J Aind phone numbernEQ J Sist all entriesn
GQ J Display total entries in databasen
FQ J Kort entriesn
>Q J Soad database from filenQ J :xitn92+
gotoxy1!7&E2+
cprintf19Please Kelect an option between ! and %92+ gotoxy1!7!E2+
printf19Database loaded8<s97dbload2+
gotoxy1!7!?2+ printf19Kelect an option 892+
optrtn * getch12+
return optrtn+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 24/30
B
-oid exitmenu1-oid2
6
char filename&Q7sa-eopt+ int k+
A,S: Mf!+
gotoxy1!7G2+ printf19Do you want to Ka-e database before exitingU 92+
gotoxy1!7&E2+
cprintf19Press H/H to conform7 anykey to cancle%92+
sa-eopt*getch12+ flushall12+
if1sa-eopt**HyHsa-eopt**H/H2
6
gotoxy1!7>2+ printf19Please :nter the Path and filename 892+
gotoxy1!7!2+ printf19(s 8 c8mydata%txt92+
gotoxy1?>7>2+
gets1filename2+ flushall12+
f! * fopen1filename79a92+
if 1f!**;ISS2
6 gotoxy1!7!&2+
fprintf1stderr79There was an error in opening your database file <s97filename2+ gotoxy1!7&E2+ cprintf19Database was not sa-ed@ 92+
getch12+
exit+ B
else
6
for 1k*+k4addcount+k))2 6
fprintf1f!79<dt<ldn97roomkQ7phonekQ2+
B fclose1f!2+
gotoxy1!7&E2+
cprintf19Database was successfilly sa-ed in <s97filename2+ getch12+
B
B
else
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 25/30
6
gotoxy1!7&E2+
cprintf19Database was not sa-ed@ 92+ getch12+
B clrscr12+
gotoxy1&07!2+ printf19Thanks for using program92+
gotoxy1&07!!2+
printf19Coded by8 (nkit Dhir92+ gotoxy1&07!02+
printf19:mail8 infoeducation%com 92+
getch12+ exit12+
B
-oid drawscreen1-oid2
6 int n+
gotoxy1!7!2+
for 1n*+n4>+n))2 cprintf19<c97!G2+
gotoxy1!7&2+
for 1n*+n40!+n))2
cprintf19 92+ cprintf19MMM P"O;: NOOW MMM92+
for 1n*+n40!+n))2 cprintf19 92+ gotoxy1!702+
for 1n*+n4>+n))2
cprintf19<c97!G2+B
-oid refreshscreen1-oid2
6
int n+ clrscr12+
textcolor1/:SSOL2+ textbackground1NROL;2+ gotoxy1!7&E2+
for 1n*+n4>+n))2
cprintf19 92+
B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 26/30
ead 5 stings, calculate lengt, co"pae, concatenate, copying codes
3include4conio%h53include4stdio%h5
main126
char str!&Q7str&&Q+ int i7strlen!*7strlen&*+
textcolor12+
clrscr12+ textattr1!2+
printf19ttt92+
cprintf19(nkit Dhir Kolutions92+
printf19n:nter first string892+
scanf19<s97str!2+ printf19n:nter Kecond Ktring892+
scanf19<s97str&2+ for1i*+str!iQ@*+i))2
strlen!))+
for1i*+str&iQ@*+i))2 strlen&))+
printf19lentgh of first string is 8<d n lentgh of second string is 8 <d97strlen!7strlen&2+
if 1strlen!**strlen&2
6 for 1i*+i4strlen!+i))2
6 if1str!iQ@*str&iQ2 goto not+
B
printf19nKtrings are same92+ B
else
6
not8 printf19nKtrings are not same92+
B
for1i*strlen!+i41strlen!)strlen&2+i))2 6
str!iQ*str&1iJstrlen!2Q+
B printf19n(fter Concatenate string ! become 8 <s97str!2+
for1i*+i41strlen!)strlen&2+i))2
6
str&iQ*str!iQ+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 27/30
B
printf19nafter copying Ktring ! is <s n Ktring & is8 <sn<d <d97str!7str&7strlen!7strlen&2+
getch12+B
Finding /i"e nu"%e
#include<stdio.h>#include<conio.h>main(){int a,b,c,d=0,e;clrscr();printf("Enter an!e ");scanf("dd",$a,$e);if (e<a)return(0);
printf("%n &rime numbers in this ran!e are %n");for (b=a;b<=e;b''){for (c=;c<b;c''){if(bc==0){d=;
brea*;++if (d==){d=0;continue;+
else{printf("d%t",b);++!etch();+
Tic Tac Toe Game in C
3include4graphics%h5
3include4iostream%h53include 4conio%h5
-oid main126start8 int a0Q0Q*6E7G7F7>77!7!!7!&7!0B7i7j7k7x7y7t7cn*7co*+
char c+
static int nod*7nn*7sc&Q*67B+nod))+
clrscr12+
int dri-er*D:T:CT7mode+
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 28/30
initgraph1=dri-er7=mode79d8tcbgi92+
setbkcolor1R:D2+
line1!7&7?7&2+line1!707?702+
line1&7!7&7?2+line107!707?2+
gotoxy1&7&2+cout449T,C T(C TO:9+
gotoxy1&702+
cout449Inregistered Yesion !%9+gotoxy1!7E2+cout449 NOX ;O 9+
gotoxy1!E7F2+cout4499+
gotoxy107F2+cout449!9+gotoxy1?E7F2+cout449&9+
gotoxy1!E7!?2+cout44909+
gotoxy107!?2+cout449?9+gotoxy1?E7!?2+cout449E9+gotoxy1!E7&!2+cout449G9+
gotoxy107&!2+cout449F9+
gotoxy1?E7&!2+cout449>9+gotoxy1EE7&&2+cout449R:KIST9+
gotoxy1EE7&02+cout449MMMMMMMMMMMMMMMMMMMMMMMMM9+
gotoxy1EE7!E2+cout449P!J944scQ+gotoxy1EE7!G2+cout449P&J944sc!Q+
for1i*+i4*&+i))2
6
for1j*+j4*&+j))26 re8gotoxy1GE7?2+
k*11i)j2<&)!2+
cout449:nter player944k+gotoxy1G7E2+
cout449 Nox no from to > 9+
gotoxy1E>7G2+cout449 Q9+gotoxy1G7G2+
t*getch12+
t*tJ?>+if1t**26x*+y*+goto play+B
if1t**!26x*!+y*+goto play+Bif1t**&26x*&+y*+goto play+B
if1t**026x*+y*!+goto play+Bif1t**?26x*!+y*!+goto play+B
if1t**E26x*&+y*!+goto play+B
if1t**G26x*+y*&+goto play+Bif1t**F26x*!+y*&+goto play+B
if1t**>26x*&+y*&+goto play+B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 29/30
else
6goto re +B
play8if11axQyQ**!21axQyQ**&22
6goto re+Bif11axQyQ@*!2==1axQyQ@*&22
6 if1k**!26circle1!Mx)!)E7!My)!)E7E2+
axQyQ*k+co))+B if1k**&2
6line1xM!)!7yM!)!7xM!)&7yM!)&2+line1xM!)!7yM!)&7xM!)&7yM!)!2+
axQyQ*k+co))+B
Bgotoxy1G7&02+
if11aQQ**a!QQ2==1a!QQ**a&QQ22
6cout449Player 944k449 wins9+cn*!+sckJ!Q))+Bif11aQQ**aQ!Q2==1aQ!Q**aQ&Q226cout449Player 944k449 wins9+cn*!+sckJ!Q))+B
if11aQQ**a!Q!Q2==1a!Q!Q**a&Q&Q22
6cout449Player 944k449 wins9+cn*!+sckJ!Q))+Bif11a!QQ**a!Q!Q2==1a!Q!Q**a!Q&Q22
6cout449Player 944k449 wins9+cn*!+sckJ!Q))+B
if11a&QQ**a&Q!Q2==1a&Q!Q**a&Q&Q226cout449Player 944k449 wins9+cn*!+sckJ!Q))+B
if11a&QQ**a!Q!Q2==1a!Q!Q**aQ&Q22
6cout449Player 944k449 wins9+cn*!+sckJ!Q))+B
if11aQ&Q**a!Q&Q2==1a!Q&Q**a&Q&Q226cout449Player 944k449 wins9+cn*!+sckJ!Q))+B
if11aQ!Q**a!Q!Q2==1a!Q!Q**a&Q!Q22
6cout449Player 944k449 wins9+cn*!+sckJ!Q))+Bif1cn**!2
6goto #ue+B
if1co**26gotoxy1G&7&02+
cout449DR(L9+
nn))+goto #ue+B
BB
#ue8gotoxy1G7&?2+
cout449Play again y$n9+
c*getch12+if11c**HyH21c**H/H22
6 goto start+B
7/24/2019 C Programming Codes
http://slidepdf.com/reader/full/c-programming-codes 30/30
else if11c**HnH21c**H;H22
6goto end+B
else goto #ue+
end8closegraph12+
cout449Ainal score is 944sckJ!Q449J944nodJnnJsckJ!Q+
gotoxy1&7!2+cout449Thanks for playing this game9+
getch12+
B