1.Flag
Code:
#include<stdio.h>
#include<graphics.h>
int main()
{
int gd = DETECT,gm;
initgraph(&gd, &gm, ” “);
circle(230,100,50);
rectangle(120,40,350,160);
rectangle(115,35,120,300);
rectangle(80,300,160,315);
rectangle(45,315,195,330);
getch();
closegraph();
return 0;
}
2. Hut
Code:
#include<graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,””);
// roof
line(150,50,400,50);
line(150,50,200,150);
line(150,50,90,130);
line(200,150,450,150);
line(400,50,450,150);
//roof left-side double line
line(151,56,90,138);
line(90,130,90,137);
//Front box
rectangle(200,150,430,250);
//left-side back wall
line(100,125,100,210);
//footer
line(75,200,200,250);
line(200,250,450,250);
line(450,250,450,275);
line(200,275,450,275);
line(200,275,75,225);
line(75,200,75,225);
//door
rectangle(275,170,345,250);
//door middle
line(310,170,310,250);
circle(305,210,5);
circle(315,210,5);
//window
line(125,130,175,150);
line(125,130,125,200);
line(175,150,175,220);
line(125,200,175,220);
//window grill hr
line(125,140,175,160);
line(125,150,175,170);
line(125,160,175,180);
line(125,170,175,190);
line(125,180,175,200);
line(125,190,175,210);
//window grill vr
line(140,136,140,206);
line(155,141,155,211);
getch();
}
3. DDA
Code:
#include<stdio.h> #include<graphics.h> int main(){ int gd=DETECT,gm; initgraph(&gd,&gm," "); //int hight=GetSystemMetrics(SM_CYSCREEN); //int width=GetSystemMetrics(SM_ CXSCREEN); //initwindow(1000,600,""); float x1,y1,x2,y2; int colorCode; printf("Enter The X1 : "); scanf("%f",&x1); printf("Enter The Y1 : "); scanf("%f",&y1); printf("Enter The X2 : "); scanf("%f",&x2); printf("Enter The Y2 : "); scanf("%f",&y2); printf("Enter The Color Code(like 10 is Green) : "); scanf("%d",&colorCode); float dellX = abs(x2-x1); float dellY = abs(y2-y1); float m = dellY/dellX; //Case 1; if(m<1){ bool conditionForLoop = true; for(int i=0;conditionForLoop==true;i++ ){ putpixel(x1,y1,colorCode); if(x1==x2 || y1==y2){ conditionForLoop = false; } x1=x1+1; y1=y1+m; delay(100); } } //Case 2; else if(m>1){ bool conditionForLoop = true; for(int i=0;conditionForLoop==true;i++ ){ putpixel(x1,y1,colorCode); if(x1==x2 || y1==y2){ conditionForLoop = false; } x1=x1+(1/m); y1=y1+1; delay(100); } } //Case 3; else if(m==1){ bool conditionForLoop = true; for(int i=0;conditionForLoop==true;i++ ){ putpixel(x1,y1,colorCode); if(x1==x2 || y1==y2){ conditionForLoop = false; } x1=x1+1; y1=y1+1; delay(100); } } getch(); closegraph(); return 0; }
4. Table
Code:
5. Chair
Code:
6. Find the second highest number of three given numbers in the prolog.
Code:
tamal:-
write(“Enter three numbers”),nl,
read(A),read(B),read(C),
com(A,B,C).
com(A,B,C):-
A<B,
A>C,
write(A),
write(” is 2nd Highest number”).
com(A,B,C):-
A>B,
A<C,
write(A),
write(” is 2nd Highest number”).
com(A,B,C):-
B<A,
B>C,
write(B),
write(” is 2nd Highest number”).
com(A,B,C):-
B>A,
B<C,
write(B),
write(” is 2nd Highest number”).
com(A,B,C):-
C<A,
C>B,
write(C),
write(” is 2nd Highest number”).
com(A,B,C):-
C>A,
C<B,
write(C),
write(” is 2nd Highest number”).
7. Find the even & odd of a given number in the prolog.
Code:
tamal:-
write(“Enter your number: “),
read(A),
even_odd(A).
even_odd(A):-
M is mod(A,2),
M = 0,
write(A),
write(” is an even number”);
M = 1,
write(A),
write(” is an odd number”).
8. Print 1 to N using loop in prolog
Code:
tamal:-
write(“Enter a target number:”),
read(A),nl,
loop(1,A).
loop(1,A):-
write(“The numbers are:”),nl,
between(1,A,B),
writeln(B),
B>=A,
!.
loop(1,A).
9. Find the possible relations of a family tree in the prolog
Code:
female(pam).
female(liz).
female(pat).
female(ann).
male(jim).
male(bob).
male(tom).
male(pit).
parent(pam,bob).
parent(tom,bob).
parent(tom,liz).
parent(bob,ann).
parent(bob,pat).
parent(pat,jim).
parent(bob,pitter).
parent(pitter,jim).
mother(X,Y):- parent(X,Y),female(X).
father(X,Y):- parent(X,Y),male(X).
haschild(X):- parent(X,_).
sister(X,Y):- parent(Z,X),parent(Z,Y),female(X),X\==Y.
brother(X,Y):-parent(Z,X),parent(Z,Y),male(X),X\==Y.