Program for enabling and disabling the keyboard.

#include "stdio.h"
#include "conio.h"
#include "dos.h"

main()
{
clrscr();
outportb(0x64,0xAD); /*Code for disabling the KEYBOARD*/
printf("Keyboard Disabled");
delay(10000);
clrscr();
printf("Keyboard Enabled");
outportb(0x64,0xAE); /*Code for enabling the KEYBOARD*/
getch();

}

Related Links :

Program for verifying the disk sector.

#include "stdio.h"
#include "conio.h"
#include "dos.h"

void main(void)
{
clrscr();
union REGS regs;
struct SREGS sregs;
char buff[1000];
int i;
regs.h.ah = 4;
regs.h.al = 1;
regs.h.ch = 1;
regs.h.dh = 0;
regs.h.cl = 1;
regs.h.dl = 0x80;
regs.x.bx = FP_OFF(buff);
sregs.es = FP_SEG(buff);
int86x(0x13,®s,®s,&sregs);
printf("regs.x.cflag - %d",regs.x.cflag);
printf("regs.h.ah - %d",regs.h.ah);
printf("regs.h.al - %d",regs.h.al);
printf("Buffer - %d",buff);
getch();
}

Related Links :

Program To transfer text and html files between two computers using three wire connections between com ports

#include"stdio.h"
#include"conio.h"
#include"process.h"
#include"dos.h"
#include"graphics.h"
#include"start.h"

void baudset(long);
void comparm(int,int,int);
int port_address;
union REGS i,o;
void main()
{
int gd=DETECT,gm,maxx,maxy,x,y,button,ex=1,c,v=1,run=1;
FILE *f;
char chr;
char *fname;
int result,status,choice,port;
unsigned int fstat,mstat,lstat;
st();
while(1)
{
initgraph(&gd,&gm," ");
cleardevice();
maxx=getmaxx();
maxy=getmaxy();
setbkcolor(9);
if(run==1)
{
gotoxy(32,1);
printf("PORT INACTIVE");
run++;
}
else
{
gotoxy(32,1);
printf("PORT ACTIVATED SUCCESSFULLY");
}

choice=0;
rectangle(0,20,maxx,maxy);
setviewport(1,5,maxx-1,maxy-1,1);
if(initmouse()==0)
{
closegraph();
restorecrtmode();
outtextxy(100,100,"mouse driver not loaded");
exit(1);
}
restrictmouseptr(1,20,maxx-1,maxy-1);
showmouseptr();
setcolor(6);
outtextxy(115,30,"WELCOME TO PROGRAM TO TRANSFER FILES BETWEEN TWO COMPUTERS");
setcolor(3);
outtextxy(430,45,"ver 1.0 ");
setcolor(14);
outtextxy(170,45,"PANKAJ A.H., 9373144662");
setcolor(10);
outtextxy(200,100,"1 : SEND FILE");
outtextxy(200,120,"2 : RECIEVE FILE");
outtextxy(200,140,"3 : EXIT");
outtextxy(200,175,"enter your choice (1,2 or 3)::");
rectangle(195,95,210,110);
rectangle(195,115,210,130);
rectangle(195,135,210,150);
setcolor(13);
outtextxy(20,450,"PRESS 'F1' TO ACTIVATE THE PORTS");
setcolor(9);
while(v==1)
{
if(kbhit())
{
chr=getch();
if(chr==0)
{
chr=getch();
c=(int)chr;
if(c==59)
{
gotoxy(31,1);
printf("PORT ACTIVATED");
v=2;
break;

}
}
}
}
while(ex==1)
{
getmousepos(&button,&x,&y);
gotoxy(5,1);
(button & 1)== 1 ? printf("DOWN"):printf("UP");

gotoxy(20,1);
(button & 2) == 2 ? printf("DOWN"):printf("UP");

gotoxy(65,1);
printf("X=%03d Y=%03d",x,y);
if((button & 1)==1)
{
if((x>=195 && x<=210) && (y>=95 && y<=110))
{
choice=1;
}
if((x>=195 && x<=210) && (y>=115 && y<= 130))
{
choice=2;
}
if((x>=195 && x<=210) && (y>=135 && y<=150))
{
choice=3;
}
}
if(choice==1 || choice==2 || choice==3)
goto sos;
if(kbhit())
{
goto sob;
}
}
fflush(stdin);
sob: gotoxy(60,12);
scanf("%d",&choice);
sos: switch(choice)
{
case 1: {
setcolor(12);
outtextxy(10,205,"select port (1: com1 2: com2) ::");
rectangle(470,200,485,215);
rectangle(510,200,525,215);
outtextxy(474,203,"1");
outtextxy(514,203,"2");
gotoxy(50,14);
scanf("%d",&port);
if(port==1)
port_address=0x3F8;
else
port_address=0x2F8;
baudset((long)2400);
comparm(0,1,8);
outport(port_address+4,1|2);
outtextxy(10,240,"enter the name of file to be sent::");
gotoxy(50,16);
scanf("%15s",&fname);
f=fopen(&fname,"r");
if(f==NULL)
{
setcolor(4);
outtextxy(10,300,"*** file do not exist ***");
setcolor(6);
outtextxy(10,320,"hit any key to continue........");
getch();
break;
}
closegraph();
restorecrtmode();
clrscr();
textcolor(2);
for(;;)
{
if(kbhit())
{
if(getch()==27)
break;
}
lstat=inportb(port_address+5);
if(!(lstat & 32))
continue;
else
{
chr=fgetc(f);
}
if(chr==EOF)
{
cprintf("FILE TRANSMITTED
);

outportb(port_address,EOF);
getch();
break;
}
outportb(port_address,chr);
putchar(chr);
}

fclose(f);
break;
}

case 2: {
setcolor(12);
outtextxy(10,205,"select port (1: com1 2: com2) ::");
gotoxy(50,14);
scanf("%d",&port);
if(port==1)
port_address=0x3F8;
else
port_address=0x2F8;
baudset((long)2400);
comparm(0,1,8);
outportb(port_address+4,1|2);
textcolor(4);
outtextxy(10,240,"save as file name::");
gotoxy(50,16);
scanf("%15s",&fname);

f=fopen(&fname,"w");
if(f==NULL)
{
setcolor(4);
outtextxy(10,300,"*** sorry cannot open file ***");
break;
}
closegraph();
restorecrtmode();
clrscr();
textcolor(4);
cprintf("waiting for i/p
);

textcolor(7);
cprintf("press esc for exit
);

gotoxy(1,4);
for(;;)
{
if(kbhit())
{
if(getch()==27)
break;
}
fstat=inportb(port_address+5);
if(fstat & 2)
cprintf("over run time error
);

if(fstat & 4)
cprintf("parity error");
if(fstat & 8)
cprintf("framing error
);

if(fstat & 16)
cprintf("break recieved
);

if(!(fstat & 1))
continue;
chr=inportb(port_address);
if(chr==EOF)
{
textcolor(2);
cprintf("FILE RECIEVED
);

exit(0);
}
putchar(chr);
fputc(chr,f);
}
outportb(port_address+4,0);
fclose(f);
break;
}

case 3: exit(0);
default: sound(900);
delay(10000);
nosound();
break;
}

}

}


void baudset(long baudrate)
{
unsigned int divisor;
unsigned char lsb,msb;
divisor=1152001/baudrate;
msb=divisor>>8;
lsb=(divisor<<8)>>8;
outportb(port_address+3,128);
outportb(port_address,lsb);
outportb(port_address+1,msb);

}


void comparm(int parity,int stop,int databit)
{
int parmbyte;
parmbyte=databit-5;
if(stop==2)
parmbyte|=4;
if(parity!=0)
parmbyte|=8;
if(parity==2)
parmbyte|=16;
outportb(port_address+3,parmbyte);
}

/* MOUSE WORK */

initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}


showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}


restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}


getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

Related Links :

Expression of a human face which smiles and cries

#include "graphics.h"
#include "stdlib.h"
#include "stdio.h"
#include "malloc.h"
#include "dos.h"
#include "conio.h"

int xasp,yasp,gdriver = VGA, gmode=VGAMED, errorcode;

struct pos
{
int x;
int y;
};

struct face
{
int radius;
struct pos position;
int mood;
};

typedef struct face face;
face *face1;

void getposition()
{
printf("Enter X Co-ordinate:");
scanf("%d",&face1->position.x);
printf("Enter X Co-ordinate:");
scanf("%d",&face1->position.y);
}

void drawface()
{

char ch='x';
int i=0,x,y,color,r,imgsize,dif;

x=face1->position.x=320;
y=face1->position.y=180;
face1->radius=150;
color=15;
r=face1->radius;

setbkcolor(0);
getaspectratio(&xasp,&yasp);
setcolor(8);
circle(x,y,face1->radius);

setfillstyle(1,color);
floodfill(x,y,getcolor());


draweyes(face1);
drawhair(face1);
drawmouth(face1);
drawnose(face1);


}

drawnose()
{
int i,x,y,r;
x=face1->position.x;
y=face1->position.y;
r=face1->radius;
setcolor(0);

for(i=0;i<2;i++) r="face1-">radius;
x1=face1->position.x-r/2;
y1=face1->position.y-r/4;
x2=face1->position.x+r/2;
y2=face1->position.y-r/4;

setaspectratio(xasp/2,yasp);
arc(x1,y1-r/8,40,140,r/4);//left eyebrow
arc(x1,y1-r/8+1,40,140,r/4);//left eyebrow
arc(x1,y1-r/8+2,40,140,r/4);//left eyebrow
setaspectratio(xasp,yasp);

for(i=0;i<2;i++) i="0;i<2;i++)" x="face1-">position.x;
y=face1->position.y+(face1->radius/1.5);
r=face1->radius;
setcolor(BLACK);

if((face1->mood)==1)
for(i=0;i<4;i++)>mood)==0)
for(i=0;i<4;i++) r="face1-">radius;
x=face1->position.x-r/2;
y=face1->position.y-r/3;

arc(x,y,34,225,100);

arc(x+r,y,314,138,100);

setfillstyle(1,RED);
floodfill(x,y-70,getcolor());
floodfill(x+r,y-70,getcolor());
setaspectratio(xasp,yasp);
}

void main(void)
{
int i=0;
initgraph(&gdriver, &gmode,"");

while(!kbhit())
{
if((i%2)==1)
{
setvisualpage(1);
setactivepage(0);
clearviewport();
face1->mood=0;
drawface();
delay(1000);
}
else
{
setvisualpage(0);
setactivepage(1);
clearviewport();
face1->mood=1;
drawface();
delay(300);
}
i++;
}

getch();
closegraph();
}

Related Links :

Convert between bases


#include
#include
#include
#include

int main()
{
int cotinue=1;
long int org_num=0, org_base=0, valid_org_val, pos_org_num, new_num, base10_num, remainder;
int new_base=0;
int pow_limit, pow_test;
int cur_term=0;
cout<
do
{
//The outermost "do...while" loop allows for repetitive revolutions of
//the primary block of the application. The program will continue to
//oscillate between the input and output pages as long as the variable
//referred to as "cotinue" is equal to "1." This variable can be changed
//through user input at the end of the output page.
do
{
//This repetition statement ensures that the base of the initial number,
//which is discovered by the program through a user input statement,
//is a value between 1 and 17 exclusively. The prompt message will
//continue to be displayed and the user will continue to be required
//to enter in the value of the base for the original number if he/she
//incessently enters invalid bases into the system.
cout<
cin>>new_base;
} while((new_base <> 16));
do
{
//This "do...while" loop will continue to run as long as the "org_num"
//variable, which sybolizes the amount of the initial number, does not
//meet specific requirements concerning the size of the first value. The
//user is expected to abide by the rules connecting the value of the
//new base and the amount of the number that must be converted,
//which are explained to the operator during the execution of the project
//with the aid of the "cout" statement below. If the first amount is too
//large or too small (in terms of a negative value) to be converted
//into the specified base, the user will be required to enter in a new
//number which fits the parameters for the new base.
cout<<"\n\nInput the integer that must be converted.\n\nIf the new base is 2, then the original number must be\ngreater than or equal to -1,000 and less than or equal to 1,000.\n\nIf the new base is > 2 and <>
cin>>org_num;
} while((((org_num < -1000) || (org_num > 1000)) && (new_base == 2)) || (((org_num < -10000) || (org_num > 10000)) && ((new_base > 2) && (new_base <> 1000000)) && (new_base > 10)));
cout<
do
{
//The nested "do...while" repetition statement will repeat as long as
//the original base of the original integer is less than 2 or greater
//than 10. Since the variable of "org_num," which stores the initial
//whole number, is an integer, the base of the first number cannot exceed
//10. If the base was allowed to exceed 10, then letters and other
//nonnumerical characters would be allowed as input into the "org_num"
//integer identifier, effectively breaking C++ syntax rules. Similar
//to the two previous "do...while" loops, this repetition unit will
//continue to execute with a prompt for user input continually being
//displayed on the monitor while the base of the starting whole number
//is less than 2 or larger than 10.
cout<<"\nWhat is the base of the initial number\n"<
cin>>org_base;
} while((org_base <> 10));
clrscr(); //Second Page Begins to Be Processed
//***Full Conversion Process Begins Below
if(org_num <>
//If it is discovered that the original number is negative, the initial amount
//is transformed into a positive value by storing the product of -1 and
//"org_num" in the identifier named "pos_org_num."
pos_org_num = org_num * -1;
else
//If "org_num" is positive or equal to 0, the value of the first whole number
//is placed in "pos_org_num."
pos_org_num = org_num;
//**Start of Conversion to Base Ten
for(pow_test=0; pow(10, pow_test) <= pos_org_num; ++pow_test);
//The above "for" loop, which does not contain a single executable statement
//but rather serves as a counter, determines the final value of "pow_test."
//"pow_test" is an integer variable that holds the first value "n" in
//the expression "1 * 10^n" such that the result of the expression
//is greater than "pos_org_num." The final value of "pow_test" also
//stores the number of single digits that are found in the positive
//form of the intial number. "pow_test" is incremented by 1 after each
//revolution through the loop, and the repetition statement will end
//when the result of "10^pow_test" is greater than the original amount
//in its positive form.
for(pow_limit=(pow_test - 1), remainder=pos_org_num, base10_num=0, valid_org_val=1; pow_limit >= 0; --pow_limit)
{
//The purpose of this "for" loop involves converting the initial amount,
//which is now present in its positive form in the variable called
//"pos_org_num," to its equivalent value in base 10. The identifier
//named "pow_limit" is initialized at an upper bound--the number of
//digits that are in "pos_org_num" subtracted by 1. "remainder,"
//an identifier that stores the amount within "pos_org_num" which have
//not been subtracted by the succeeding processes, is set to the positive
//form of "org_num." "base10_num" is an accumulator that holds the current
//result of the conversion process of "pos_org_num" into a base 10 value.
//On the other hand, "valid_org_val" is initialized to 1, signifying
//that the program assumes at first that all digits in "pos_org_num"
//are less than the original base that the value is in. This loop will
//continue to execute as long as "pow_limit" is greater that -1, and
//the value stored in "pow_limit" will decrement by 1 at the end of each
//revolution.
cur_term = (remainder / pow(10, pow_limit));
//The above assignment statement allows the computer to identify any
//digit that lies within "pos_org_num."
if(cur_term >= org_base)
{
//If the current term that is being analyzed in the "for" loop is
//discovered to be greater than or equal to the base that the amount
//was originally in, "pow_limit" is set to -1 (the outer "for" loop
//will terminate when "pow_limit" is less than 0) and "valid_org_base"
//is assigned the value of 0, signifying that the orginal value does
//not coincide with its suggested original base.
pow_limit=-1;
valid_org_val=0;
}
base10_num = (base10_num + (cur_term * pow(org_base, pow_limit)));
//The previous value of "base10_num" is added to the current digit that
//was pulled from the positive form of the initial number times the result
//of the number's original base raised to the current value of "pow_limit."
//After the surrounding repetition statement is finished executing,
//"base10_num" will contain the value of the original amount converted
//into base 10 number representation. This process is performed to
//improve the logical pathway involved in transforming a number in any
//base that is less than 10 into its equivalent amount in a second base
//that is under 10.
remainder = (remainder - (pow(10, pow_limit) * cur_term));
//The updated version of "remainder" is found by raising 10 to the current
//value for "pow_limit," multiplying the result by the digit that is being
//analyzed from the intial amount, and subtracting the product from the
//previous value of "remainder."
}
//**End of Base Ten Conversion
if(valid_org_val == 0)
//If the original number contains digits that exceed or equal the first
//number's base, an error message will be outputted and the program will
//ask the operator if he/she wants to attempt the conversion stage again.
cout<<"\n\n\n\nError: The Base and the Value of the Original Number Do not Coincide";
else
{
//This block of code will be accessed by the computer if all of the digits
//in the initial number are less than the base that the number is supposedly in.
cout<<"\n\n\n\nThe conversion of "<
for(pow_test=0; pow(new_base, pow_test) <= base10_num; ++pow_test);
//Although the above "for" loop lacks a body, its heading serves as
//a counter for the number of characters that lie within the newly
//created "base10_num" variable. The loop's control variable, which
//is referred to as "pow_test," will increment by one after each run
//through the loop, and the loop will continue to execute while the
//result of "new_base ^ pow_test" is less than or equal to the base 10
//conversion of the positive form of the original number.
if(new_base <>
{
//If the base that the intial value is being converted over to is
//less than 11, then the following segment of code is performed.
for(pow_limit=(pow_test-1), remainder=base10_num, new_num=0; pow_limit >= 0; --pow_limit)
{
//The purpose of this repetition statement is to convert the newly
//developed "base10_num" variable into the new base that was
//specified by the user.
//This "for" loop initializes "pow_limit," which symbolizes the digit
//that is being reviewed within "base10_num" in terms of scientific
//notation, to the difference of "pow_test" minus 1. In addition,
//"remainder," a variable that holds the amount in "base10_num"
//that has not been subtracted from the variable's original value
//by the following operations, is first set to equal "base10_num."
//The sum of the conversion process of "base10_num" to the number's
//new base is set to a starting value of 0. The loop's control variable
//of "pow_limit" decreases by 1 following each successful cycle of the
//repetition statement's body, and the loop's body will continue
//to execute as long as "pow_limit" is not less than 0.
cur_term = pow(new_base, pow_limit);
//The current term or digit that will be divided by "base10_num"
//is calculated and stored in "cur_term" by raising the original
//integer's new base to the value of "pow_limit."
new_num = new_num + (pow(10, pow_limit) * (remainder / cur_term));
//The value of "new_num," which represents the current progress of
//converting the original whole number to the new base, is found
//by raising 10 to "pow_limit," multiplying the result by the outcome
//of "remainder" divided by "cur_term," and adding the product to
//the previous value of "new_num."
remainder = (remainder - ((remainder / cur_term) * cur_term));
//The new value of "remainder" stores the current amount residing
//in "base10_num" which have not been "touched" by the division
//and conversion processes.
}
if(org_num <>
//If the original amount is discovered to be negative, the positive
//form of "new_num" will become negative by multiplying "new_num"
//by -1.
new_num = new_num * -1;
cout<
}
else
{
//If the new base is not between 2 and 10, inclusively, then an entirely
//different process must be performed to reveal the proper answer.
//Instead of storing the converted solution to the original number in
//a variable, the individual characters, including letters and numbers,
//are printed on the monitor as they are discovered.
for(pow_limit=(pow_test-1), remainder=base10_num; pow_limit >= 0; --pow_limit)
{
//This "for" loop is designed to calculate and display each value
//of the conversion's solution character-by-character. The loop's
//control variable (or "pow_limit") is initialized at "pow_test - 1,"
//which reveals the number of digits that exist in the number stored
//in "base10_num." On the other hand, "remainder" is first set to
//equal "base10_num." The loop's control variable decrements by 1
//at the conclusion of each revolution through the loop, and the
//loop will run as long as "pow_limit" is not less than 0.
cur_term = pow(new_base, pow_limit);
//The current "term" of the conversion process is calculated by
//raising the new base to the current value for "pow_limit." For
//instance, if "new_base" is 6 and "pow_limit" is equivalent to
//3, then "cur_term" equals 216.
if((remainder / cur_term) <>
//If the newly discovered character in the solution is a number
//that is less than 10, then the numerical form of the single
//digit is displayed on the screen with the aid of the
//output statement that is written below.
cout<<(remainder / cur_term);
else
//If the new character in the problem's solution is a value
//which is greater than 9, then the letter form of the new number
//is displayed to the user. For example, if the new element is
//12, the letter "C" will be displayed instead of "12."
cout<
remainder = (remainder - ((remainder / cur_term) * cur_term));
//The above line of code determines the new value of "remainder,"
//which contains the amount of "base10_num" that has not been affected
//by the program.
}
}
}
//***End of Full Base Conversion
cout<<"\n\n\n\n\n\n\n\tWould you like to run the conversion process again?\n\t\t\t\t(1 = Yes, 2 = No)\n\t\t\t\t\t";
//The above output statement and the input line below require the user to
//choose whether he/she would like to cycle through the base conversion
//process again. If the operator enters a "1," the first screen of the
//application will reappear. If the user presses any key other than "1,"
//the project will terminate.
cin>>cotinue;
clrscr();
} while(cotinue == 1);
return 0;
}

Related Links :

Showing Binary Equivalent of an Integer

main()
{
int n;
char ch;
while(1)
{
clrscr();
printf("Enter an integer to see its Binary Equivalent");
printf("Enter ");
scanf("%d",&n);
showbits(n);

printf("continue ? ");
ch=getch();
if(ch==27)
break;
}
}

showbits(int n)
{
int i,bit,mask,count=0;
printf(" ");
for(i=15;i>=0;i--)
{
mask=1<

bit=n & mask;

if(bit==mask)
printf("1");
else
printf("0");
count++;
if(count%4==0)
printf(" ");
}
}

Related Links :

A Program to find permutation in c

#include "stdio.h"
#include "stdlib.h"
int lev=-1,n,val[50],a[50];
void main()
{
int i,j;
clrscr();
printf("Enter howmany numbers ");
scanf("%d",&n);
for(i=0;i
{
val[i]=0;
j=i+1;
scanf("%d",&a[j]);
}
visit(0);
getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i
printf("%2d",a[val[i]]);
printf(" ");
}
for(i=0;i
if(val[i]==0)
visit(i);
lev--;
val[k]=0;
}

Related Links :

Program to Create n-sized triangle.

/* Print a Triangle of Stars on it's tip
Input: a positive integer
Output: an n-sized triangle */
void Triangle(int s)
{
int i = 0;

while (s > 0)
{
for (i = 0; i < s; i++)
{
printf("*");
}
printf("\n");
s = s - 1;
}
}

/* Print a Triangle of Stars on it's base
Input: a positive integer
Output: an n-sized triangle */
void TriangleTwo(int t)
{
int i = 0;
int x = 0;
int y = 1;
int counter = 0;

while (counter < t)
{
x = t - (t - y);

for (i = 0; i < x; i++)
{
printf("*");
}
printf("\n");
y++;
counter++;
}
}




**************


void TriangleTwo(int t)
{
if (t < 1)
return; /* base case */
else
{
TriangleTwo(t - 1); /* recursive step */

while(t > 0)
{
printf("*");
t--;
}
printf("\n");

}
}





*****************

void printIt(int row, int star)
{
if(row)
{
putchar('*');
--star;
if(star == 0)
{
putchar('\n');
star = row - 1;
--row;
}
printIt(row, star);
--row;
}
else
{
return;
}
}



**********************

// Print n asterisks and a newline
void asterisks(int n)
{
if (n <= 0)
putchar('\n');
else
{
putchar('*');
asterisks(n - 1);
}
}

// Descending triangle (large at top, small at bottom)
void t1(int n)
{
if (n > 0)
{
asterisks(n);
t1(n - 1);
}
}

// Ascending triangle (small at top, large at bottom)
void t2(int n)
{
if (n > 0)
{
t2(n - 1);
asterisks(n);
}
}


**********************



/* Print a Triangle of Stars on it's tip
Input: a positive integer
Output: an n-sized triangle */
void Triangle(int s)
{

if (s == 1)
printf("*"); /* base case */
else
{
for(int i = 1; i <= s; i++)
{
printf("*");
}
printf("\n");
Triangle(s - 1); /* recursive step */
}
}

/* Print a Triangle of Stars on it's base
Input: a positive integer
Output: an n-sized triangle */
void TriangleTwo(int t)
{
if (t < 1)
return; /* base case */
else
{
TriangleTwo(t - 1); /* recursive step */

while(t > 0)
{
printf("*");
t--;
}
printf("\n");

}
}



Related Links :

Employee Project in C

#include "stdio.h"
main()
{
FILE*fp,*ft;
char another,choice;

struct emp
{
char name [20];
int age;
float bs;
};

struct emp e;
char empname[40];
long int recsize;
fp=fopen("EMP.DAT","rb+");

if(fp==NULL)
{
fp=fopen("EMP.DAT","wb+");
exit();
}

recsize=sizeof(e);

while(1)
{
clrscr();
printf("\n 1.Add records");
printf("\n 2.List records");
printf("\n 3.Modifay records");
printf("\n 4.Delete records");
printf("\n 0.Exit");
printf("\n Enter your choice");

fflush (stdin);
choice=getche();

switch(choice)
{
case '1':
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
printf("\n enter name age and basic salary");
scanf("%s %d %f",&e.name,&e.age,&e.bs);
fwrite(&e,recsize,1,fp);
printf("\n add another records(y/n)");
fflush(stdin);
another=getche();
}
break;

case '2':
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
printf("\n %s %d %f",e.name,e.age,e.bs);
getch();
break;

case '3':
another='y';
while(another=='y')
{
printf("\n enter name of employee to modify");
scanf("%s",&empname);

rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{
if(strcmp(e.name,empname)==0)
{
printf("\n enter new name age and bs");
scanf("%s %d %f",&e.name,&e.age,&e.bs);
fseek(fp,-recsize,SEEK_CUR);
fwrite(&e,recsize,1,fp);
break;
}
}
printf("\nmodify another record(y/n)");
fflush(stdin);
another=getche();
}
break;

case '4':

another ='y';
while(another=='y')
{
printf("\n enter name of employee to delete");
scanf("%s",&empname);
ft=fopen("TEMP.DAT","wb");
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{
if(strcmp(e.name,empname)!=0)
fwrite(&e,recsize,1,ft);
}
fclose(fp);
fclose(ft);

remove("EMP.DAT");
rename("TEMP.DAT","EMP.DAT");

fp=fopen("EMP.DAT","rb+");
printf("delete another record(y/n)");
fflush(stdin);
another=getche();
}
break;
case '0':
fclose(fp);
exit();
}
}
}

Related Links :

Program to Create, Read & write Using File in C

#include "stdio.h"
main()
{
FILE *fp;
char a[80];
int z;
p:
printf("\n1.Write");
printf("\n2.Read");
printf("\n3.Out");
printf\nEnter U R Choice...");
scanf("%d",&z);
switch(z)
{
case 1:
{
fp = fopen("aa.txt","w");
if(fp==NULL)
{
puts("cant get me");
exit();
}
printf("\nEnter new line...\m");
while(strlen(gets(a))>0)
{
fputs(a,fp);
puts("\n");
}
fclose(fp);
getch();
goto p;
}
}

case 2:
{
fp = fopen("aa.txt","r");
if(fp==NULL)
{
puts("cant get me");
exit();
}
while(fgets(a,79,fp)!=NULL)
printf("%s",a);
fclose(fp);
getch();
goto p;
}
}

Related Links :

Use of OR Operator in C

main()
{
char name;
clrscr();
printf("\n enter 1 letter of your name");
scanf(" %c",&name);
if(name=='r'||name=='R')
{
printf("\n your name is ram");
}
else
printf("\n who are you");
getch();
}

Related Links :

Program to generate a fibonaci number Series in C

main()
{
int n,T ;
clrscr();
printf(" program to generate a fibonaci number");
scanf("d",&n);
fib(n);
return 0;
}
fib( int T )

{
int flast = 1, slast = 0;
int curname;
printf(" febonacci number :\n");
printf("\n");
do
{
curname =flast+slast;
printf("%u\n",curname);
slast=flast;
flast=curname;
T--;
}
while(T>1);
return;
getch();
}


Related Links :

Program to get imagenary Roots

#include"stdio.h"
#include"conio.h"
#include"math.h"
main()
{
int a,b,c;
float r1,r2,v1,v2;
clrscr();
printf("enter value of a,b,c");
scanf("%d %d %d",&a,&b,&c);
v1=(b*b)-(4*a*c);
if(v1<0)
{
printf("%f",v1);
printf("\n the root are imagenary");
}
else
v2=sqrt(v1);
r1=((-b)+v2)/(a*2);
r2=((-b)-v2)/(2*a);
printf("answer=%f\t%f",r1,r2);
getch();
}

Related Links :

Debit Credit Project in C

main()
{
int accno[10],amt[10],de,cr;
int i=1,j,z;

aa:
clrscr();
printf("\n 1. add record...");
printf("\n 2. debit..");
printf("\n 3.credit...");
printf("\n 4.disply..");
printf("\n 5.exit..");
printf("\n enter your choice number ....\n");
scanf("%d",&z);
switch(z)
{
case 1:
{
printf("enter accno & opening amount.....\n");
scanf("%d %d",&accno[i],&amt[i]);
i=i+1;
}
getch();
goto aa;

case 2:
printf("Enter the Accno & debit amount...\n");
scanf("%d %d",&accno,&de);
amt[j]=amt[j]+de;
getch();
goto aa;

case 3:
printf("\nEnter the Accno & credit amount..\n");
scanf("%d %d",&accno,&cr);
amt[j]=amt[j]-cr;
printf("%d",amt[j]);
getch();
goto aa;

case 4:
clrscr();
printf("Accno & Amount....\n");
printf("====================");
for(j=1;j{
printf("\n%d %d",accno[j],amt[j]);
}
getch();
goto aa;

case 5:
break;
}

}

Related Links :

Program to show getpixel() application

#include "graphics.h"

void main()
{
int driver = DETECT,mode;
int i;

initgraph(&driver,&mode,"c:\\borlandc\\bgi");
line(100,100,500,100);
for ( i = 20; i < 300; i++ )
if ( getpixel(300,i) == WHITE )
{
setcolor(BLUE);
circle(300,i,5);
}
else
putpixel(300,i,WHITE);
getch();
closegraph();
}

Related Links :

program to draw a interesting picture using line

#include "graphics.h"
#include "math.h
#include "conio.h"

void main(void)
{
int driver = DETECT,mode;
int x[10],y[10];
int x_center = 360, y_center = 180, rad = 100;
int i,j;

initgraph(&driver,&mode,"c:\\tc\\bgi");
for ( i = 0; i <>
{
x[i] = x_center + rad * cos(36*i*3.14159/180);
y[i] = y_center + rad * sin(36*i*3.14159/180);
}
for ( i = 0; i <>
for ( j = 0; j <>
line(x[i],y[i],x[j],y[j]);
getch(); /* press any key return to TEXT mode */
closegraph();
}

Related Links :


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!