Você está na página 1de 8

//Program to Draw Basic Circle Using Graphics in C

#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm, c:\\turboc3\\bgi
circle(200,100,150);

);

getch();
closegraph();
}
</conio.h></graphics.h>
/* InitGraph initializes the graph package.
GraphDriver has two valid values:
GraphDriver=0 which performs an auto detect
and initializes the highest possible mode with the most colors.
1024x768x64K is the highest possible resolution
supported by the driver, if you need a higher resolution,
you must edit MODES.PPI.
If you need another mode,
then set GraphDriver to a value different
from zero and graphmode to the mode
you wish (VESA modes where 640x480x256 is 101h etc.).
PathToDriver is only needed,
if you use the BGI fonts from Borland.
Free Pascal does not offer BGI fonts like Borland,
these must be obtained separately.
Example code:
var
gd,gm : integer;
PathToDriver : string;
begin
gd:=detect; { highest possible resolution }
gm:=0; { not needed, auto detection }
PathToDriver:='C:\PP\BGI'; { path to BGI fonts,
drivers aren't needed }
InitGraph(gd,gm,PathToDriver);
if GraphResult<>grok then
halt; ..... { whatever you need }
CloseGraph; { restores the old graphics mode }
end.
*/
//Program to implement Circle Drawing Algorithm
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
class myCircle
{
private:

int x,y,r,d,x1,y1;
public:
myCircle();
//Constructor
void showCircle();
};
myCircle::myCircle()
{
x=0;y=0;
cout<<"
"Enter The Co-Ordinates Of The Circle ":=";
cin>>x>>y;
cout<<"
"Enter The Radius Of The Circle ":=";
cin>>r;
}
void myCircle::showCircle()
{
char *s;
x1=0;y1=r;
d=3-2*r;
while(x1<=y1)
{
putpixel((x+x1+320),(y+y1+240),5);
putpixel((x-x1+320),(y+y1+240),5);
putpixel((x+x1+320),(y-y1+240),5);
putpixel((x-x1+320),(y-y1+240),5);
putpixel((x+y1+320),(y+x1+240),5);
putpixel((x-y1+320),(y+x1+240),5);
putpixel((x+y1+320),(y-x1+240),5);
putpixel((x-y1+320),(y-x1+240),5);
if(d<0)
d+=4*x1+6;
else
{
d+=4*(x1-y1)+10;
y1--;
}
x1++;
}
setcolor(5);
outtextxy(318+x,235+y,".");
setcolor(15);
sprintf(s,"Center(%d,%d)",x,y);
outtextxy(20,10,"The Center Is At");
outtextxy(20,20,s);
sprintf(s,"Radius=%d",r);
outtextxy(20,30,s);
getch();
}
void main()
{
int gd=DETECT,gm,i,j,xx=190,xxx=480;
clrscr();
myCircle a;
char *mess[]={"B","R","E","S","E","N","H","A","M","'","S"," ","C","I","R
","C","L","E"," ","A","L","G","O","R","I","T","H","M"};
initgraph(&gd,&gm,"..\bgi");
cleardevice();

//

rectangle(120,40,320,240);
rectangle(320,40,520,240);
rectangle(120,240,320,440);
rectangle(320,240,520,440);
for(i=0,j=27;i<16,j>=14;i++,j--)
{
xx+=10;
outtextxy(xx,10,mess[i]);
xxx-=10;
outtextxy(xxx,10,mess[j]);
delay(100);
}
for(i=130;i<=510;i+=10)
for(j=50;j<=430;j+=10)
putpixel(i,j,15);
for(i=130;i<=510;i+=10)
{
if(i==320)
continue;
outtextxy(i,237,"+");
}
for(i=50;i<=430;i+=10)
{
if(i==240)
continue;
outtextxy(317,i,"-");
}
outtextxy(310,230,"O");
outtextxy(530,240,"X");
outtextxy(320,450,"-Y");
outtextxy(100,240,"-X");
outtextxy(320,30,"Y");
a.showCircle();
closegraph();
}

//Program to create rectangle


#include<graphics.h>
main()
{
int driver,mode,i=10;
driver=0;
mode=VGAHI;
initgraph(&driver,&mode,"\\tc\\bgi");
for(i=10;i<=100;i+10)
{
rectangle(254,236,456,368);
clearviewpart();
delay(500);
moveto(i,i);
}
getch();
restorecrtmode();
closegraph();
}
</graphics.h>
// Program to create Analog and Digital clock in C

# include <graphics.h>
# include <stdio.h>
# include <dos.h>
# include <string.h>
# include <math.h>
# define pi 3.141592654
int x;
float x30,x60,y30,y60;
void paint1()
{
setcolor(GREEN);
outtextxy(297,60," ");
outtextxy(297,332," ");
outtextxy(435,198," ");
outtextxy(160,198," ");
setcolor(RED);
outtextxy(375,85,"");
outtextxy(420,260,"");
outtextxy(170,135,"");
outtextxy(220,310,"");
setcolor(LIGHTBLUE);
outtextxy(420,135,"");
outtextxy(375,310,"");
outtextxy(220,83,"");
outtextxy(175,260,"");
}
void paint2()
{
setcolor(RED);
outtextxy(297,60,"");
outtextxy(297,332,"");
outtextxy(435,198,"");
outtextxy(160,198,"");
setcolor(LIGHTBLUE);
outtextxy(375,85,"");
outtextxy(420,260,"");
outtextxy(170,135,"");
outtextxy(220,310,"");
setcolor(GREEN);
outtextxy(420,135," ");
outtextxy(375,310," ");
outtextxy(220,83," ");
outtextxy(175,260," ");
}
void paint3()
{
setcolor(LIGHTBLUE);
outtextxy(297,60,"");
outtextxy(297,332,"");
outtextxy(435,198,"");
outtextxy(160,198,"");
setcolor(GREEN);
outtextxy(375,85," ");
outtextxy(420,260," ");
outtextxy(170,135," ");
outtextxy(220,310," ");
setcolor(RED);
outtextxy(420,135,"");
outtextxy(375,310,"");
outtextxy(220,83,"");

outtextxy(175,260,"");
}
void graph()
{
cleardevice();
setcolor((++x)%15+1);
if(x%2)
outtextxy(180,10,"THERE IS NO GOD EXCEPT ALLAH");
else
outtextxy(130,20,"PRAISE ALLAH THE MOST BENEFICIENT AND MERCIFUL");
setcolor(GREEN);
circle (300,200,150);
circle(300,200,2);
setcolor(14);
circle (300,200,100);
setcolor(3);
circle (300,200,120);
setcolor(RED);
circle(300,50,2);
circle(450,200,2);
circle(150,200,2);
circle(300,350,2);
setcolor(BLUE);
circle(300+x30,200+y30,2);//1
circle(300-x30,200+y30,2);//11
circle(300+x30,200-y30,2);//5
circle(300-x30,200-y30,2);//7
circle(300+x60,200+y60,2);//2
circle(300+x60,200-y60,2);//4
circle(300-x60,200-y60,2);//8
circle(300-x60,200+y60,2);//10
if(x%2)
{
setcolor(x);
outtextxy(300+x30*1.1,200+y30*1.1,"1");//1
outtextxy(300-x30*1.1,200+y30*1.1,"11");//11
outtextxy(300+x30*1.1,200-y30*1.1,"5");//5
outtextxy(300-x30*1.1,200-y30*1.1,"7");//7
outtextxy(300+x60*1.1,200+y60*1.1,"2");//2
outtextxy(300+x60*1.1,200-y60*1.1,"4");//4
outtextxy(300-x60*1.1,200-y60*1.1,"8");//8
outtextxy(300-x60*1.15,200+y60*1.1,"10");//10
outtextxy(460,200,"3");
outtextxy(300,360,"6");
outtextxy(140,200,"9");
outtextxy(290,40,"12");
}
}
void plot(int h , int m , int s)
{
char a[2],b[2],c[2];
setcolor( LIGHTCYAN );
itoa(h,a,10);
outtextxy(450,100,a);
outtextxy(470,100,":");
itoa(m,a,10);

outtextxy(490,100,a);
outtextxy(510,100,":");
itoa(s,a,10);
outtextxy(530,100,a);
setcolor( LIGHTGREEN );
if( h<13 )
outtextxy( 290 , 250 , "AM");
else
outtextxy( 290 , 250, "PM");
h=h%12;
setlinestyle(SOLID_LINE , 1 , 3);
setcolor( RED );
line(300,200,300+floor(100*cos(((h*5+m/10.0)*6-90)*pi/180)),
200+floor(100*sin(((h*5+m/10.0)*6-90)*pi/180)));
setcolor(BLUE);
setlinestyle(SOLID_LINE,1,3);
line(300,200,300+floor(120*cos((m*6-90)*pi/180)),
200+floor(120*sin((m*6-90)*pi/180)));
setcolor(MAGENTA);
setlinestyle(SOLID_LINE,1,1);
line(300,200,300+floor(120*cos((s*6-90)*pi/180)),
200+floor(120*sin((s*6-90)*pi/180)));
}
void timexy()
{
int h,m,s;
struct time t;
while(1)
{
//clrscr();
cleardevice();
graph();
gettime(&t);
//printf("

The current time is:


%2d:%02d:%02d.%02d
",
//
t.ti_hour, t.ti_min, t.ti_sec,t.ti_hund);
h=t.ti_hour;
m=t.ti_min;
s=t.ti_sec;
if(s%3==0)
paint1();
else if(s%3==1)
paint3();
else paint2();
plot(h,m,s);
delay(995);
}

}
main()
{
int i=DETECT,m;
char a[100],b[10]="jalpari";
x30=floor(150*cos((30-90)*pi/180));
y30=floor(150*sin((30-90)*pi/180));
x60=floor(150*cos((60-90)*pi/180));
y60=floor(150*sin((60-90)*pi/180));
initgraph(&i,&m,"d:\tc\bgi");
i=0;
printf("
PASSWORD==>");
do
{
a[i]=getch();
if(!(a[i]==(char)13))
{
printf("vasim");
i++;
}
else {a[i]='
</math.h></string.h></dos.h></stdio.h></graphics.h>
//write a program to draw some basic shapes.
#include<graphics.h>
#include<conio.h>
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();
}
</conio.h></graphics.h>
//
C Program to find twin prime numbers, twin Prime Numbers by using C language
void main()
{

int n,i,k,r,ary[50],p;
clrscr();
printf(" Enter Maximum Value For Numbers: ");
scanf("%d",&r);
i=1;
p=0;
while(i<=r)
{
k=0;n=1;
while(n<=i)
{
if(i%n==0)
k++;
n++;
}
if(k==2)
{
ary[p]=i;
p++;
}
i++;
}
for(n=0;n<p;n++)
{
if(ary[n+1]-ary[n]==2)
printf("\n %d and %d are TWIN PRIME Numbers ",ary[n],ary[n+1]);
}
getch();
}

Você também pode gostar