To find the roots of a quadratic equation.

Logic : The roots of any quadratic equation of the the form, are,The same equation is computerized here. The program asks user to enter the three coefficients a, b and c. Then it finds out numerator- which is the discriminate, and the denominator of the equation of the roots. Then it checks if the numerator is greater, equals or less than zero. Prints out the results according to the situation.

This can be elaborated to find the roots of equation with higher powers. You are pleased to contact us with your doubts through the discussion forum.







#include
#include
void main()
{
int A, B, C;
float disc, deno, x1, x2;
clrscr();
printf(“\n\n\t ENTER THE VALUES OF A,B,C…”);
scanf(“%d,%d,%d”, &A, &B, &C);
disc = (B * B) – (4 * A * C);
deno = 2 * A;
if(disc > 0)
{
printf(“\n\t THE ROOTS ARE REAL ROOTS”);
x1 = (-B/deno) + (sqrt(disc) / deno);
x2 = (-B/deno) – (sqrt(disc) / deno);
printf(“\n\n\t THE ROOTS ARE…: %f and %f\n”, x1, x2);
}
else if(disc == 0)
{
printf(“\n\t THE ROOTS ARE REPEATED ROOTS”);
x1 = -B/deno;
printf(“\n\n\t THE ROOT IS…: %f\n”, x1);
}
else
printf(“\n\t THE ROOTS ARE IMAGINARY ROOTS\n”);
getch();
}




Related Links :

To find the biggest and smallest number and positions in the given array


Logic: The entered array is traced through the dimension. Initially the program assumes the first member is the smallest and the greatest till now. In each iteration, the stored min and max number is checked if the present number is smaller than the min, or larger than max stored. If so, the present number is overwritten on the old value. Finally the lowest and highest members will be stored in min and max respectively.

We demonstrated the algorithm, by taking the integer array. It is also possible to work with the array of other data types also.





#include
void main()
{
int A[25], max, min, maxpos, minpos, n, i;
clrscr();
printf(“\n\n\t ENTER THE SIZE OF THE ARRAY…: “);
scanf(“%d”, &n);
printf(“\n\n\t ENTER THE ELEMENTS OF THE ARRAY…: “);
for(i=1; i<=n; i++) { gotoxy(25, 15+i); scanf(“%d”, &A[i]); } max = A[1]; maxpos = 1; for(i=1; i<=n; i++) { if(max<=n; i++) { if(min>A[i])
{
min = A[i];
minpos = i;
}
}
printf(“\n\n\t THE LARGEST ELEMENT IS…: %d”, max);
printf(“\n\n\t AND ITS POSSITION IS…: %d”, maxpos);
printf(“\n\n\tTHE SMALlEST ELEMENT IS…: %d”, min);
printf(“\n\n\t AND ITS POSSITION IS…: %d”, minpos);
getch();
}

Related Links :

write a program to draw some basic shapes.



#include
#include

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, “”);

circle(100,100,50);
outtextxy(75,170, “Circle”);
rectangle(200,50,350,150);
outtextxy(240, 170, “Rectangle”);
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, “Ellipse”);
line(100,250,540,250);
outtextxy(300,260,”Line”);

sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, “Sector”);
drawpoly(6, poly);
outtextxy(340, 460, “Polygon”);
getch();
closegraph();
}

Related Links :

C progrma for First Come First Serve Algorithm


#include
#include
#include
void main()
{
clrscr();
int p[20],b[20],w[20],t[20],i,v,n,at;
int wt=0;
float tw,tr;
printf("Enter the number of process : ");
scanf("%d",&n);
printf("enter CPU burst time : ");

for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
t[1]=b[1];
w[1]=0;
at=t[1];
wt=w[1];
for(i=2;i<=n;i++)
{
t[i]=b[i]+t[i-1];
at=at+t[i];
w[i]=t[i-1];
wt=wt+w[i];
}
}
printf("process \t burst_time \t wait_time \t turn_around \t \n");
for(i=1;i<=n;i++)
{
printf("%d \t\t %d \t\t %d \t\t %d",i,b[i],w[i],t[i]);
printf("\n");
}
printf("\n average wait time");
tw=wt/n;
printf("%f",tw);
printf("\n Average turn around time");
tr=at/n;
printf("%f",tr);
getch();
}

Related Links :

C program for Macro Processor


#include
#include
#define getx1y1
printf("Enter the order of Ist Matrix:");
scanf("%d%d",&x1,&y1);

#define getx2y2
printf("Enter the order of IIst Matrix:");
scanf("%d%d",&x2,&y2);

#define inputa
printf("Enter the value of a:");
for(i=0;i<=x1;i++) inputb="" enter="" value="" of="" addab="" k="0;k

Related Links :

C program for Syntax Analyzer


#include
#include
#include
#include
void main()
{
int i,j,k=0,count,inc=0,n;
char name[30],open[30],ch,chh,o[30];
char op[20]={'=','+','-','*','/','%','^','&','|'};
clrscr();
textcolor(3);
cprintf("--Syntax Analyser--");
printf("\n");
printf("\n Enter Syntax");
printf("\n");
scanf("%s",name);
n=strlen(name);
for(i=0;i {
ch=tolower(name[i]);
for(j=0;j<9;j++)
{
if(ch==op[j])
{
open[k]=i;
o[k]=ch;
k++;
}
}
}
for(i=0;i {
count=open[i];
ch=tolower(name[count-1]);
chh=tolower(name[count+1]);
if(isalpha(ch)&&isalpha(chh)||isdigit(chh))
++inc;
}
if(k==inc)
printf("\n %s is a valid syntax",name);
else
printf("\n %s is an invalid syntax",name);
getch();
}

Related Links :

C program for Round Robin



#include
#include
#include
int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav;
int allover()
{
for(int i=0;i0)
return 0;
return 1;
}
void select(int p)
{
w[p]+=t-lat[p];
if(ct[p]>=s)
{
ct[p]-=s;
t+=s;
}
else
{
t+=ct[p];
ct[p]=0;
}
if(ct[p]==0)
ta[p]=t;
lat[p]=t;
}
void main()
{
int p=0;t=0;taav=0;wav=0;
clrscr();
printf("Enter the number of process : ");
scanf("%d",&n);
printf("\n Enter the time slice : ");
scanf("%d",&s);
printf("\nEnter the burst time of processes \n ");
for(int i=0;i

Related Links :

Radix Sort in C



#define NUMELTS 100
# include
#include
#include
void radixsort(int a[],int);
void main()
{
int n,a[20],i;
clrscr();

printf(" enter the number :");
scanf("%d",&n);
printf(" ENTER THE DATA -");
for(i=0;i {
printf("%d. ",i+1);
scanf("%d",&a[i]);
}
radixsort(a,n);
getch();
}
void radixsort(int a[],int n)
{
int rear[10],front[10],first,p,q,exp,k,i,y,j;
struct
{
int info;
int next;
}node[NUMELTS];
for(i=0;i {
node[i].info=a[i];
node[i].next=i+1;
}
node[n-1].info=a[n-1];
node[n-1].next=-1;
first=0;

for(k=1;k<=2;k++) //consider only 2 digit number
{
for(i=0;i<10;i++)
{
front[i]=-1;
rear[i]=-1;
}

while(first!=-1)
{
p=first;
first=node[first].next;
y=node[p].info;
exp=pow(10,k-1);
j=(y/exp)%10;
q=rear[j];
if(q==-1)
front[j]=p;
else
node[q].next=p;
rear[j]=p;
}
for(j=0;j<10&&front[j]==-1;j++)
;
first=front[j];
while(j<=9)
{
for(i=j+1;i<10&&front[i]==-1;i++)
;
if(i<=9)
{
p=i;
node[rear[j]].next=front[i];
}
j=i;
}
node[rear[p]].next=-1;
}
//copy into original array
for(i=0;i{
a[i]=node[first].info;
first=node[first].next;

}
clrscr();
textcolor(YELLOW);
cprintf(" DATA AFTER SORTING:");
for(i=0;i printf("%d . %d",i+1,a[i]);
}

Related Links :

Radix Sort in C



#define NUMELTS 100
# include
#include
#include
void radixsort(int a[],int);
void main()
{
int n,a[20],i;
clrscr();

printf(" enter the number :");
scanf("%d",&n);
printf(" ENTER THE DATA -");
for(i=0;i {
printf("%d. ",i+1);
scanf("%d",&a[i]);
}
radixsort(a,n);
getch();
}
void radixsort(int a[],int n)
{
int rear[10],front[10],first,p,q,exp,k,i,y,j;
struct
{
int info;
int next;
}node[NUMELTS];
for(i=0;i {
node[i].info=a[i];
node[i].next=i+1;
}
node[n-1].info=a[n-1];
node[n-1].next=-1;
first=0;

for(k=1;k<=2;k++) //consider only 2 digit number
{
for(i=0;i<10;i++)
{
front[i]=-1;
rear[i]=-1;
}

while(first!=-1)
{
p=first;
first=node[first].next;
y=node[p].info;
exp=pow(10,k-1);
j=(y/exp)%10;
q=rear[j];
if(q==-1)
front[j]=p;
else
node[q].next=p;
rear[j]=p;
}
for(j=0;j<10&&front[j]==-1;j++)
;
first=front[j];
while(j<=9)
{
for(i=j+1;i<10&&front[i]==-1;i++)
;
if(i<=9)
{
p=i;
node[rear[j]].next=front[i];
}
j=i;
}
node[rear[p]].next=-1;
}
//copy into original array
for(i=0;i{
a[i]=node[first].info;
first=node[first].next;

}
clrscr();
textcolor(YELLOW);
cprintf(" DATA AFTER SORTING:");
for(i=0;i printf("%d . %d",i+1,a[i]);
}

Related Links :

Search An Element in Linked List in C


#include
#include
#include
struct node
{
int data;
struct node*next;
};
void insert(struct node**p,int num) /*Function for inserting an
element into a list */

{
if(*p==NULL)
{
(*p)=(struct node*)malloc(sizeof(struct node));
(*p)->next=NULL;
(*p)->data=num;
}
else
{
insert(&((*p)->next),num);
}
}

void display(struct node*p) /*Function for displaying the list*/
{
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}


void reverse(struct node**p) /*Function for reversing the list by
recursion */
{
struct node*q,*r,*x;
int d;
q=(*p); /*stores the address of the first element */
x=q; /*also stores the element of the first element for
counter pourpose */
d=q->data; /*stores the data of the first element*/
r=q->next; /*stores the address of the second element in the list
*/
free(q); /*deletes the first element of the list*/
if(x==NULL)
return ;
else
{
reverse(&(r));/*Recursive call*/
insert(p,d); /*This function is put in the stack so the first
will be taken as last element for the new list */
}
}

void main()
{
clrscr();
struct node*p=NULL;
int n,d,i=0;
printf("How many...?");
scanf("%d",&n);
while(i++!=n)
{
scanf("%d",&d);
insert(&p,d);
}
display(p);
reverse(&p);
printf("The reversed list is...");
display(p);
getch();
}


Related Links :

Micky Mouse Program In C

Logic : Here we divided the the employee into three categories according to his basic pay. The first category is getting the basic pay less than Rs.5000/-. Second category is having the basic between Rs.5000/- to Rs.10000/-, and the third is getting the basic more than Rs.10000/-. Basic idea here is to calculate the DA and TAX amount according to the category.
Finally it calculates the desired two as,
Gross = Basic + DA+ HRA and,
Net = Gross- ( PF + Tax ).




#include
#include
#include
#include
void *buf;
void firstleft();
void secondleft();
void main()
{
int gd=DETECT,gm,i=0,x,y,area;
initgraph(&gd,&gm,"tc:\bgi");\put your directory contains egavga.bgi
rectangle(0,0,getmaxx(),getmaxy());
arc(240,120,40,140,70);
ellipse(165,80,10,280,20,20);
ellipse(315,80,-100,170,20,20);
arc(235,120,163,215,70);
arc(245,120,-35,17,70);
ellipse(193,178,85,280,40,20);
ellipse(283,178,-100,95,40,20);
ellipse(238,199,180,0,39,50);
ellipse(213,123,44,240,33,40);
ellipse(262,123,-60,135,33,40);
ellipse(210,123,0,360,13,20);//left eye
ellipse(265,123,0,360,13,20);//right eye
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);
moveto(183,350);
lineto(173,460);
lineto(213,460);
lineto(238,400);
lineto(263,460);
lineto(303,460);
lineto(293,350);
moveto(173,460);
lineto(143,478);
lineto(213,478);
lineto(213,460);
moveto(263,460);
lineto(263,478);
lineto(333,478);
lineto(303,460);
line(238,400,238,350);
//right hand
moveto(183,260);
lineto(113,310);
lineto(183,375);
moveto(183,280);
lineto(137,310);
lineto(181,353);
setfillstyle(2,13);
floodfill(190,300,15);
setfillstyle(1,5);
floodfill(223,400,15);
setfillstyle(1,5);
floodfill(253,400,15);
setfillstyle(1,6);
floodfill(173,470,15);
floodfill(303,470,15);
//fingers
secondleft();
ellipse(413.5,228,0,180,3.5,3.5);
line(420,240,433,240);
line(423,247,440,247);
line(413,240,410,228);
line(417,228,420,240);
ellipse(433,243.5,-90,90,3.5,3.5);
line(423,254,440,254);
ellipse(440,250.5,-90,90,3.5,3.5);
ellipse(430,257,-90,90,3,3);
line(413,260,430,260);
area=imagesize(409,224,444,261);
buf=malloc(area);
getimage(409,224,444,261,buf);
while(!kbhit())
{
if(i==0)
{
setfillstyle(1,15);
setcolor(15);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
setcolor(0);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(391,209,buf,1);
firstleft();
setcolor(15);
secondleft();
putimage(409,224,buf,0);
i=1;
}
else
{
setfillstyle(1,0);
setcolor(0);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
floodfill(210,133,0);
floodfill(265,133,0);
setcolor(15);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(409,224,buf,1);
secondleft();
setcolor(15);
firstleft();
putimage(391,209,buf,0);
i=0;
}
delay(300);
}
getch();
}
void firstleft()
{
moveto(293,260);
lineto(353,276);
lineto(395,223);
moveto(293,280);
lineto(355,296);
lineto(395,245);
}
void secondleft()
{
moveto(293,260);
lineto(363,280);
lineto(413,240);
moveto(293,280);
lineto(363,300);
lineto(413,260);
}

Related Links :

Micky Mouse Program In C


#include
#include
#include
#include
void *buf;
void firstleft();
void secondleft();
void main()
{
int gd=DETECT,gm,i=0,x,y,area;
initgraph(&gd,&gm,"tc:\bgi");\put your directory contains egavga.bgi
rectangle(0,0,getmaxx(),getmaxy());
arc(240,120,40,140,70);
ellipse(165,80,10,280,20,20);
ellipse(315,80,-100,170,20,20);
arc(235,120,163,215,70);
arc(245,120,-35,17,70);
ellipse(193,178,85,280,40,20);
ellipse(283,178,-100,95,40,20);
ellipse(238,199,180,0,39,50);
ellipse(213,123,44,240,33,40);
ellipse(262,123,-60,135,33,40);
ellipse(210,123,0,360,13,20);//left eye
ellipse(265,123,0,360,13,20);//right eye
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);
moveto(183,350);
lineto(173,460);
lineto(213,460);
lineto(238,400);
lineto(263,460);
lineto(303,460);
lineto(293,350);
moveto(173,460);
lineto(143,478);
lineto(213,478);
lineto(213,460);
moveto(263,460);
lineto(263,478);
lineto(333,478);
lineto(303,460);
line(238,400,238,350);
//right hand
moveto(183,260);
lineto(113,310);
lineto(183,375);
moveto(183,280);
lineto(137,310);
lineto(181,353);
setfillstyle(2,13);
floodfill(190,300,15);
setfillstyle(1,5);
floodfill(223,400,15);
setfillstyle(1,5);
floodfill(253,400,15);
setfillstyle(1,6);
floodfill(173,470,15);
floodfill(303,470,15);
//fingers
secondleft();
ellipse(413.5,228,0,180,3.5,3.5);
line(420,240,433,240);
line(423,247,440,247);
line(413,240,410,228);
line(417,228,420,240);
ellipse(433,243.5,-90,90,3.5,3.5);
line(423,254,440,254);
ellipse(440,250.5,-90,90,3.5,3.5);
ellipse(430,257,-90,90,3,3);
line(413,260,430,260);
area=imagesize(409,224,444,261);
buf=malloc(area);
getimage(409,224,444,261,buf);
while(!kbhit())
{
if(i==0)
{
setfillstyle(1,15);
setcolor(15);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
setcolor(0);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(391,209,buf,1);
firstleft();
setcolor(15);
secondleft();
putimage(409,224,buf,0);
i=1;
}
else
{
setfillstyle(1,0);
setcolor(0);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
floodfill(210,133,0);
floodfill(265,133,0);
setcolor(15);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(409,224,buf,1);
secondleft();
setcolor(15);
firstleft();
putimage(391,209,buf,0);
i=0;
}
delay(300);
}
getch();
}
void firstleft()
{
moveto(293,260);
lineto(353,276);
lineto(395,223);
moveto(293,280);
lineto(355,296);
lineto(395,245);
}
void secondleft()
{
moveto(293,260);
lineto(363,280);
lineto(413,240);
moveto(293,280);
lineto(363,300);
lineto(413,260);
}

Related Links :

Runner game in C



#include
#include
#include
void main()
{
int driver=DETECT,mode,j=100,i=0,x1,x22,x2,x11,y1,y11,y2,y22,a,y,k,speed;
float ang1=3.839724354,ang2=5.585053606, c1=0.05,
c2=-0.05,var1=2.967059728,var2=5.410520681,d1=0.072,d2=-0.072,s=2.35619449
;
initgraph(&driver,&mode,"C:\tc\bgi");
printf("

Enter the number of rounds
"); scanf("%d",&k);
printf("
Enter 1 for fast speed or 2 for normal speed
");

scanf("%d",&speed);
if(speed==1) speed=11; else speed=16;cleardevice();delay(1000);
while(k>=1)
{
while(i<=700)
{setcolor(8);
circle(i,j,22);line(i,j+22,i-13,j+115);
x1=i+50*cos(ang1);x2=i+50*cos(ang2);
y1=j+22-50*sin(ang1);y2=j+22-50*sin(ang2);
x11=x1+45*cos(ang1+1.54532952);
x22=x2+45*cos(ang2+1.54532952);
y11=y1-45*sin(ang1+1.54532952);
y22=y2-45*sin(ang2+1.54532952);
setcolor(RED);

line(i,j+22,x1,y1);line(x1,y1,x11,y11);
setcolor(GREEN);
line(i,j+22,x2,y2);
line(x2,y2,x22,y22);
x1=i-15+60*cos(ang1);
x2=i-15+60*cos(ang2);
y1=j+115-60*sin(ang1);
y2=j+115-60*sin(ang2);
x11=x1+60*cos(var1);
x22=x2+60*cos(var2);
y11=y1-60*sin(var1);
y22=y2-60*sin(var2);

line(i-13,j+115,x1,y1);
line(x1,y1,x11,y11);
setcolor(RED);
line(i-13,j+115,x2,y2);
line(x2,y2,x22,y22);
ang1=ang1+c1;
ang2=ang2+c2;
var1=var1+d1;
var2=var2+d2;
if(i==0) a=x22;
if(ang1<=3.839724354)
{
c1=0.05;
var1=2.967059728;d1=0.072;
}

if(ang1>=5.585053606){c1=-0.05;
var1=5.410520681;
d1=-0.072;a=x11+10;
s=2.356
19449;
}
if(ang2<=3.839724354)
{
c2=0.05;
var2=2.967059728;
d2=0.072;
}
if(ang2>=5.585053606)
{
c2=-0.05;
var2=5.410520681;
d2=-0.072;a=x22+10;
s=2.35619449;
}
i=a+150*cos(s)+50;
j=320-150*sin(s)-20;
s=s-0.045;
delay(speed);
if(k!=1)
cleardevice();
}
i=0;
k--;
}
getch();
}

Related Links :

Shoot The Devil game in c

Shoot The Devil game in c




#include
#include
#include "graphics.h"
#include
#include
#include

void exitmessage(void);
void lost(void);

void main()
{
randomize();
int gd=DETECT,gm,no=0,area,maxx,maxy,chance=0;
int ch,x=25,y=25,xdir=1,ydir=1,x1=20,y1,x1dir=0,area1;
void *buff,*cuff;
initgraph(&gd,&gm,"bgi");
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(50,50,15); //
floodfill(50,50,WHITE);
arc(25,25,335,360,40);
arc(75,25,180,205,40);
circle(42,45,2);
circle(54,45,2);
setfillstyle(SOLID_FILL,BLACK);
floodfill(42,45,15);
floodfill(54,45,15); //draw devil
setcolor(10);
area=imagesize(25,25,75,75);
buff=malloc(area);
getimage(25,25,75,75,buff);
putimage(25,25,buff,XOR_PUT); //erase devil
maxx=getmaxx();
maxy=getmaxy();
y1=maxy/2;
setcolor(15);
setfillstyle(SOLID_FILL,15);
rectangle(10,y1,12,y1+2); //
floodfill(11,y1+1,15); //draw bullet
area1=imagesize(10,y1,12,y1+2);
cuff=malloc(area1);
getimage(10,y1,12,y1+2,cuff);
putimage(10,y1,cuff,XOR_PUT); //erase bullet
setcolor(14);
rectangle(0,0,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);
settextstyle(1,0,3);
settextjustify(1,1);
delay(4000);
setcolor(15);
while(no<100) no="0;" ch="getch();" ch="=" x1dir="1;" ch="=" x1dir="=" y1="y1-10;" ch="=" x1dir="=" y1="y1+10;" ch="=" x1="x1+10*x1dir;" x="x+(xdir*random(30));" y="y+(ydir*random(20));">=maxx-71) //keep devil within screen
{
xdir*=-1;
x=maxx-71;
}
if(x<=175&&xdir==1) x=175; if(x<=175&&xdir==-1) xdir*=-1; if(y>=maxy-71)
{
ydir*=-1;
y=maxy-71;
}
if(y<=30) { ydir*=-1; y=30; } // if(x1>=maxx-3||x<=1) //failed chance { x1=20; x1dir=0; } if(y1>=maxy-20) //keep gun within screen
y1=maxy-21;
if(y1<=20) y1=21; // if(x1<=x+40&&x1>=x+12&&y1<=y+38&&y1>=y+10) //successful hit
{
moveto(maxx/2,maxy/2);
outtextxy(maxx/2,maxy/2,"...YOU'VE...WON...");
sound(500);
delay(5000);
nosound();
delay(3000);
exit(0);
}
}
while(chance<=10); if(chance=11) lost(); getch(); closegraph(); restorecrtmode(); } void exitmessage() { char cho; outtextxy(getmaxx()/2,getmaxy()/2,"EXIT : Y or N..."); delay(100); flushall(); cho=getch(); if(cho=='y'||cho=='Y') exit(0); else if(cho=='n'||cho=='N') { clearviewport; return; } } void lost() { outtextxy(getmaxx()/2,getmaxy()/2-50,"Your bullets are over"); outtextxy(getmaxx()/2,getmaxy()/2,"The devil destroys the world"); }

Related Links :

Snake Game in C



#include
#include
#include
#include
#include
#include

check();
end();
win();
int m[500],n[500],con=20,TEMP;
clock_t start,stop;

void main(void)
{

int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100;
int a=0,i=0,j,t,temp;
initgraph(&gd,&gm,"..\bgi");

setcolor(WHITE);
settextstyle(3,0,6);
outtextxy(200,2," SNAKE 2 BY RAJESH ");
settextstyle(6,0,2);
outtextxy(20,80," Use Arrow Keys To Direct The Snake ");
outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of
Snake");
outtextxy(20,160," Pick The Beats Untill You Win The Game ");
outtextxy(20,200," Press 'Esc' Anytime To Exit ");
outtextxy(20,220," Press Any Key To Continue ");

outtextxy(20,220," DONT FORGET TO GIVE U R VALUABLE OPINION ");
ch=getch();
if(ch==27) exit(0);
cleardevice();
maxx=getmaxx();
maxy=getmaxy();

randomize();

p=random(maxx);
temp=p%13;
p=p-temp;
q=random(maxy);
temp=q%14;
q=q-temp;



start=clock();
while(1)
{

setcolor(WHITE);
setfillstyle(SOLID_FILL,con+5);
circle(p,q,5);
floodfill(p,q,WHITE);

if( kbhit() )
{
ch=getch(); if(ch==0) ch=getch();
if(ch==72&& a!=2) a=1;
if(ch==80&& a!=1) a=2;
if(ch==75&& a!=4) a=3;
if(ch==77&& a!=3) a=4;
}
else
{
if(ch==27
) break;
}

if(i<20){>=20)

{
for(j=con;j>=0;j--){
m[1+j]=m[j];
n[1+j]=n[j];
}
m[0]=x;
n[0]=y;

setcolor(WHITE);
setfillstyle(SOLID_FILL,con);
circle(m[0],n[0],8);
floodfill(m[0],n[0],WHITE);

setcolor(WHITE);
for(j=1;j=5) spd=spd-5; else spd=5;
if(con>490) win();
p=random(maxx); temp=p%13; p=p-temp;
q=random(maxy); temp=q%14; q=q-temp;
}
if(a==1) y = y-14; if(y<0) temp="maxy%14;y="maxy-temp;}" a="="2)" y =" y+14;">maxy) y=0;
if(a==3) x = x-13; if(x<0) temp="maxx%13;x="maxx-temp;}" a="="4)" x =" x+13;">maxx) x=0;
if(a==0){ y = y+14 ; x=x+13; }
}

}


check(){
int a;
for(a=1;a

Related Links :

Program Or Project to calculate Transportation Cost in c

Program to calculate Transportation Cost in c


#include
#include

main()
{
int flag=0,flag1=0;
int s[10],d[10],sn,eop=1,dm,a[10][10];
int i,j,sum=0,min,x[10][10],k,fa,fb;

clrscr();
/* Getting The Input For the Problem*/

printf("Enter the number of Supply
");
scanf("%d",&sn);
printf("Enter the number of Demand
");
scanf("%d",&dm);
printf("Enter the Supply Values
");
for(i=0;i=d[j]) //Check the supply greater than equal to
demand
{
x[i][j]=a[i][j]*d[j]; // Calculate amount * demand
s[i]=s[i]-d[j]; // Calculate supply - demand
j++; // Increment j for the deletion of the row
or
column
}

}
/* The Cost Matrix is Estimated here */
printf("Given Cost Matrix is :
");
for(fa=0;fa



Related Links :

Program to hide the partation of your disk drive in c.


#include
#include
#include
#include

typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;

enum BOOL {TRUE=0,FALSE=1};
struct PARTITIONINFO {
BYTE bootid; /* bootable? 0=no, 128=yes */
BYTE beghead; /* beginning head number */
BYTE begsect; /* beginning sector number */
BYTE begcyl; /* 10 bit nmbr, with high 2 bits put in begsect */
BYTE systid; /* Operating System type indicator code */
BYTE endhead; /* ending head number */
BYTE endsect; /* ending sector number */
BYTE endcyl; /* also a 10 bit nmbr, with same high 2 bit trick */
DWORD relsect; /* first sector relative to start of disk */
DWORD numsect; /* number of sectors in partition */
};

struct DISK_ADD_PACKET {
BYTE recordsize;
BYTE reserved;
WORD count;
DWORD transferadd;
DWORD lowbits;
DWORD highbits;
};
struct MBR{
BYTE codes[446];
struct PARTITIONINFO partition[4];
WORD mbrid;
};
struct driveinfo{
DWORD startsect;
BYTE sysid;
};
WORD ExtentionCheck (BYTE drive)
{
union REGS regs;
regs.h.ah = 0x41;
regs.x.bx = 0x55aa;
regs.h.dl = drive;
int86(0x13,®s,®s);
if(regs.x.bx != 0xaa55)
return FALSE;
return TRUE;
}

WORD ReadSect(BYTE disk, int nsects,DWORD lsects,void* data)
{

union REGS iregs,oregs;
struct SREGS sregs;
int count=0;
struct DISK_ADD_PACKET * p;
p = (struct DISK_ADD_PACKET *)malloc(sizeof(struct DISK_ADD_PACKET));
p->recordsize=sizeof(struct DISK_ADD_PACKET);
p->count=nsects;
p->transferadd=(DWORD)data;
p->lowbits=lsects;
p->highbits=0; /* We dont need to access HD > 2TB */
iregs.h.ah = 0x42;
iregs.h.dl = disk;
iregs.x.si = FP_OFF(p);
sregs.ds = FP_SEG(p);
int86x(0x13,&iregs,&oregs,&sregs);
if(oregs.h.ah==0)
{
free(p);
return TRUE;
}

free(p);
return FALSE;

}
WORD WriteSect(BYTE disk, int nsects,DWORD lsects,void* data)
{

union REGS iregs,oregs;
struct SREGS sregs;
int count=0;
struct DISK_ADD_PACKET * p;
p = (struct DISK_ADD_PACKET *)malloc(sizeof(struct DISK_ADD_PACKET));
p->recordsize=sizeof(struct DISK_ADD_PACKET);
p->count=nsects;
p->transferadd=(DWORD)data;
p->lowbits=lsects;
p->highbits=0; /* We dont need to access HD > 2TB */
iregs.x.ax = 0x4302;
iregs.h.dl = disk;
iregs.x.si = FP_OFF(p);
sregs.ds = FP_SEG(p);
int86x(0x13,&iregs,&oregs,&sregs);
if(oregs.h.ah==0)
{
free(p);
return TRUE;
}

free(p);
return FALSE;

}
DWORD lsect=0;
void main()
{
BYTE disk=0x80;
WORD nsect=1,index=0,i=0,hi,choice;
DWORD extsect;
BYTE hideindex[5],id;
struct MBR *mbr;
struct driveinfo dinfo[10];//max 10 partitions
mbr=(struct MBR *)malloc(sizeof(struct MBR));
if(ExtentionCheck(disk)==FALSE)
{printf("extended int 13 is not supported
");
exit(1);
}


if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
for(i=0;i<4;i++)
if(mbr->partition[i].systid!=0)
{printpart(mbr,i);
dinfo[index].startsect=lsect;
dinfo[index].sysid=mbr->partition[i].systid;
index++;
}
if(mbr->partition[1].systid==0xf)//0xf for extended partition
{lsect=mbr->partition[1].relsect;
extsect=lsect;
link:
if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
{printpart(mbr,0);
dinfo[index].startsect=lsect;
dinfo[index].sysid=mbr->partition[0].systid;
index++;
if(index>=10){printf("no of partition exceed max limit");exit(1);}
if(mbr->partition[1].systid!=0)
{lsect=extsect+mbr->partition[1].relsect;
goto link;
}
}

}

printf("


Hide partition(1)
");
printf("Revele partition(2)
");
printf("Quit(3)
Enter your choice(1/2/3):");
hideindex[0]=getche();
choice=atoi(hideindex);
switch(choice)
{
case 1:
printf("
Which drive do u want to hide:(0-%d):",index-1);
scanf("%s",hideindex);
hi=atoi(hideindex);
if(hi<=index)
{
id=dinfo[hi].sysid;
if(id==1||id==4||id==7||id==0xb||id==0xc||id==0xe)
{ lsect=dinfo[hi].startsect;
id+=0x10;
if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
{mbr->partition[0].systid=id;
if(WriteSect(disk,nsect,lsect,(char *)mbr)==TRUE)
printf("
HIDDEN SUCCESSFULLY");
}
}
else
printf("Cant Hide");
}
break;
case 2:
printf("
Which drive do u want to Revele:(0-%d):",index-1);
scanf("%s",hideindex);
hi=atoi(hideindex);
if(hi<=index)
{
id=dinfo[hi].sysid;
if(id==0x11||id==0x14||id==0x17||id==0x1b||id==0x1c||id==0x1e)
{ lsect=dinfo[hi].startsect;
id-=0x10;
if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
{mbr->partition[0].systid=id;printf("%x",mbr->partition[0].systid);
if(WriteSect(disk,nsect,lsect,(char *)mbr)==TRUE)
printf("
REVELED SUCCESSFULLY");
}
}
else
printf("Cant Revele
");
}

break;
case 3:
exit(1);break;
default:
printf("
invalid choice");exit(1);
break;
};

}
printpart(struct MBR *mbr,WORD i)
{
BYTE bootable[]="YES";
BYTE id[7];
static BYTE c=0,index=0;
if(c==0)//to execute this for once
{
clrscr();
gotoxy(30,1);
printf("Partition Table");
gotoxy(2,2);
printf("INDEX");
gotoxy(8,2);
printf("SystemID");
gotoxy(17,2);
printf("Bootable");
gotoxy(26,2);
printf("StartingLBA");
gotoxy(38,2);
printf("SIZEINSECTORS");
gotoxy(52,2);
printf("SIZEINGB");
c++;
gotoxy(46,20);
printf("Coded by Tapan Kumar Mishra");
gotoxy(55,21);
printf("7th Sem,Electrical Engg.");
gotoxy(55,22);
printf("IGIT Sarang,Orissa");
gotoxy(46,23);
printf("Email id:titu_igit@rediffmail.com");
}
if(mbr->partition[i].bootid!=0x80)
strcpy(bootable,"NO");
gotoxy(2,3+index);
printf("%d",index);
gotoxy(8,3+index);
systemid((BYTE)mbr->partition[i].systid,id);
printf("%s",id);
gotoxy(17,3+index);
printf("%s",bootable);
gotoxy(26,3+index);
printf("%ld",mbr->partition[i].relsect+lsect);
gotoxy(38,3+index);
printf("%ld
",mbr->partition[i].numsect);
gotoxy(52,3+index);
printf("%5.2fGB",(float)mbr->partition[i].numsect/2097152.0);


index++;
return 0;
}
systemid(BYTE systid,BYTE *id)
{
switch(systid)
{
case 00:
strcpy(id,"empty");
break;
case 01:
strcpy(id,"FAT12");
break;
case 04:
strcpy(id,"FAT16");
break;
case 05:
strcpy(id,"EXTNED");
break;
case 0xb:
strcpy(id,"FAT32");
break;
case 0xc:
strcpy(id,"FAT32");
break;
case 0xE:
strcpy(id,"FAT16");
break;
case 0xf:
strcpy(id,"EXNDED");
break;
case 0x82:
strcpy(id,"SWAP");
break;
case 0x83:
strcpy(id,"EXT2fs");
break;
case 0x11:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x1b:
case 0x1c:
case 0x1e:
case 0x1f:
strcpy(id,"hidden");
break;


}

}

Related Links :

Program to crack the User password of Windows 7, Hacking Windows Vista or 7

Program to crack the User password of Windows 7, Hacking Windows Vista or 7
Use the program at your own risk we are not responsible for any data loss this is just for experimental purpose not for commercial use.



# include
# include
# include
# include
# include
# include
# include

unsigned char huge Data[100001];
unsigned char keystream[1001];
int Rpoint[300];

void main(int argc,char *argv[]){
FILE *fd;
int i,j;
int size;
char ch;
char *name;
int cracked;
int sizemask;
int maxr;
int rsz;
int pos;
int Rall[300]; /* Resourse allocation table */

if(argc<2){ fd="fopen(argv[1]," fd="=" size="0;" name="argv[1];">2)name=argv[2];
printf("Username:%s
",name);

/* Copy encrypted text into keystream */
cracked=size-0x0208;
if(cracked<0)cracked=0;>1000)cracked=1000;
memcpy(keystream,Data+0x208,cracked);

/* Generate 20 bytes of keystream */
for(i=0;i<20;i++){ ch="toupper(name[i]);" ch="=" ch="=" cracked="20;" sizemask="keystream[0]+(keystream[1]<<8);" i="0;i<256;i++){">maxr)maxr=Data[i];
}
}

maxr=(((maxr/16)+1)*16); /* Resourse pointer table size appears to be
divisible by 16 */

/*Search after resources */

Rpoint[0]=0x0208+2*maxr+20+2; /* First resources */
for(i=0;i>8) & 0x00ff;
}
cracked+=maxr*2+2;
printf("%d Bytes of ketstream recoverd
",cracked);

/* Decrypt resources */
for(i=0;icracked)rsz=cracked;
printf("Resource[%d](%d)
",i,rsz);
for(j=0;j


Related Links :

Program to create Basic Shapes and Colors in C using Graphics.h

Program to create Basic Shapes and Colors in C using Graphics.h



#include
#include

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, “”);

circle(100,100,50);
outtextxy(75,170, “Circle”);
rectangle(200,50,350,150);
outtextxy(240, 170, “Rectangle”);
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, “Ellipse”);
line(100,250,540,250);
outtextxy(300,260,”Line”);

sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, “Sector”);
drawpoly(6, poly);
outtextxy(340, 460, “Polygon”);
getch();
closegraph();
}

Related Links :

Program to Draw Basic Circle Using Graphics in C

Program to Draw Basic Circle Using Graphics in C

#include
#include

void main()
{
int gd=DETECT, gm;

initgraph(&gd, &gm, “c:\\turboc3\\bgi ” );
circle(200,100,150);

getch();
closegraph();
}

Related Links :

Program to find the total number of palindrome Characters in a given string.

Program to find the total number of palindrome Characters in a given string.




#include
#include
int strpalidi(char str[50], int st, int ed);
void main()
{
char str[50];
int palid = 0, len = 0, i, start = 0, end;
clrscr();
printf(“\n\n\t ENTER A SENTENCE…: “);
gets(str);
while(str[len]!=’\0′)
len++;
len–;
for(i=0;i<=len;i++) { if((str[i] == ‘ ‘ && str[i+1] != ‘ ‘) || i == len)
{
if(i == len)
end = i;
else
end = i – 1;
if( strpalidi (str, start, end ) )
palid++;
start = end + 2;
}
}
printf(“\n\n\t THE TOTAL NUMBER OF palidINDROMES FOUND ARE..: %d”,palid);
getch();
}
int strpalidi(char str[50], int st, int ed)
{
int i, palid=0;
for(i=0; i<=(ed-st)/2; i++)
{
if(str[st+i] == str[ed-i])
palid = 1;
else
{
palid = 0;
break;
}
}
return palid;
}

Related Links :

Program to check whether given number palindrome or Not.

Program to check whether given number palindrome or Not.




#include
#include
int stpal(char str1[50], char str2[50]);
void main()
{
char str[50], rev[50];
int pal;
clrscr();
printf(“\n\n\t ENTER ANY STRING…: “);
gets(str);
pal = stpal(str, rev);
printf(“\n\t THE REVERSED OF THE STRING IS…: “);
puts(rev);
if(pal)
printf(“\n\t THE ENTERED STRING IS A PALINDROME”);
else
printf(“\n\t THE ENTERED STRING IS NOT A PALINDROME”);
getch();
}

// Function Section.
int stpal(char str1[50], char str2[50])
{
int i = 0, len = 0, r = 0, pal = 1;
while(str1[len]!=’\0′)
len++;
for(i=len-1; i>=0; i–)
{
str2[r] = str1[i];
r++;
}
str2[r] = ‘\0′;
for(i=0; i<=len-1; i++)
{
if(str1[i] == str2[i])
pal = 1;
else
{
pal = 0;
break;
}
}
return pal;
}

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!!!