Friday, 20 December 2013
Clock illustration
Write a program to illustrate a clock??
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define WBC 5
//^watchbackcolor
#define X 200
#define Y 200
void dial(int x, int y);
void sechand(int timeminute);
void minhand(int t)
{
int x1,y1;
setlinestyle(0,0,3);
x1= X+ (80 * cos(t*0.1047));
y1= Y+ (80 * sin(t*0.1047));
setcolor(BLACK);
line( X, Y, x1, y1);
setcolor(WBC+1);
line( X, Y, X+ 80 * cos((t-1)*0.1047),Y+ 80 * sin((t-1)*0.1047));
circle(X,Y,4);
}
void sechand(int t)
{
int x1,y1;
setlinestyle(0,0,3);
x1= X+(100 * cos(t*0.1047));
y1= Y+(100 * sin(t*0.1047));
setcolor(RED);
line(X, Y, x1, y1);
setcolor(WBC+1);
line(X, Y, X+ 100 * cos((t-1)*0.1047),Y+ 100 * sin((t-1)*0.1047));
circle(X,Y,4);
}
void dial(int x,int y)
{
int const size=200;
setfillstyle(1,WBC);
fillellipse(x,y,size,size);
setfillstyle(1,WBC+1);
fillellipse(x,y,size-20,size-20);
outtextxy(x,y-(size-40),"12");
outtextxy(x,y+(size-40),"6");
outtextxy(x+(size-40),y,"3");
outtextxy(x-(size-40),y,"9");
outtextxy(x+size/3,y-2*size/3,"1");
outtextxy(x+2*size/3,y-size/3,"2");
outtextxy(x+2*size/3,y+size/3,"4");
outtextxy(x+size/3,y+2*size/3,"5");
outtextxy(x-size/3,y+2*size/3,"7");
outtextxy(x-2*size/3,y+size/3,"8");
outtextxy(x-size/3,y-2*size/3,"11");
outtextxy(x-2*size/3,y-size/3,"10");
circle(x,y,4);
}
void main()
{
int gd=DETECT, gm,i,j, flag=1;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
dial(200,200);
do
{
minhand(i);
for(j=0;j<60;j++)
{
sechand(j);
delay(1000
);
if(kbhit()) {
flag =0;
break;
}
}
i++;
}while(flag);
closegraph();
}
output:
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define WBC 5
//^watchbackcolor
#define X 200
#define Y 200
void dial(int x, int y);
void sechand(int timeminute);
void minhand(int t)
{
int x1,y1;
setlinestyle(0,0,3);
x1= X+ (80 * cos(t*0.1047));
y1= Y+ (80 * sin(t*0.1047));
setcolor(BLACK);
line( X, Y, x1, y1);
setcolor(WBC+1);
line( X, Y, X+ 80 * cos((t-1)*0.1047),Y+ 80 * sin((t-1)*0.1047));
circle(X,Y,4);
}
void sechand(int t)
{
int x1,y1;
setlinestyle(0,0,3);
x1= X+(100 * cos(t*0.1047));
y1= Y+(100 * sin(t*0.1047));
setcolor(RED);
line(X, Y, x1, y1);
setcolor(WBC+1);
line(X, Y, X+ 100 * cos((t-1)*0.1047),Y+ 100 * sin((t-1)*0.1047));
circle(X,Y,4);
}
void dial(int x,int y)
{
int const size=200;
setfillstyle(1,WBC);
fillellipse(x,y,size,size);
setfillstyle(1,WBC+1);
fillellipse(x,y,size-20,size-20);
outtextxy(x,y-(size-40),"12");
outtextxy(x,y+(size-40),"6");
outtextxy(x+(size-40),y,"3");
outtextxy(x-(size-40),y,"9");
outtextxy(x+size/3,y-2*size/3,"1");
outtextxy(x+2*size/3,y-size/3,"2");
outtextxy(x+2*size/3,y+size/3,"4");
outtextxy(x+size/3,y+2*size/3,"5");
outtextxy(x-size/3,y+2*size/3,"7");
outtextxy(x-2*size/3,y+size/3,"8");
outtextxy(x-size/3,y-2*size/3,"11");
outtextxy(x-2*size/3,y-size/3,"10");
circle(x,y,4);
}
void main()
{
int gd=DETECT, gm,i,j, flag=1;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
dial(200,200);
do
{
minhand(i);
for(j=0;j<60;j++)
{
sechand(j);
delay(1000
);
if(kbhit()) {
flag =0;
break;
}
}
i++;
}while(flag);
closegraph();
}
output:
Rainbow
Write a Program to draw Rainbow??
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver = DETECT,gmode;
int x,y,i;
initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
x=getmaxx()/2;
y=getmaxy()/2;
for(i=30;i<200;i++)
{
delay(100);
setcolor(i/10);
arc(x,y,0,180,i-10);
}
getch();
}
output:
Factorial of Number
Write a program to find factorial of a number??
# include <iostream.h>
# include <conio.h>
int main()
{
int Number, Factorial_Result, loop_v;
Factorial_Result=1;
cin>>Number;
for(loop_v=1;loop_v<=Number;loop_v++)
{
Factorial_Result=Factorial_Result*loop_v;
}
cout<<Factorial_Result;
return 00;
}
Output:
5
120
# include <iostream.h>
# include <conio.h>
int main()
{
int Number, Factorial_Result, loop_v;
Factorial_Result=1;
cin>>Number;
for(loop_v=1;loop_v<=Number;loop_v++)
{
Factorial_Result=Factorial_Result*loop_v;
}
cout<<Factorial_Result;
return 00;
}
Output:
5
120
Sum of n Numbers
Write a Program to find Sum of n numbers??
#include<iostream.h>
#include<conio.h>
int main()
{
int n_limit, result_sum, loop_v;
cout<<"Enter N Limit: ";
cin>>n_limit;
result_sum=0;
for(loop_v=0;loop_v<n_limit;loop_v++);
{
result_sum=result_sum+loop_v;
}
cout<<result_sum;
return 00;
}
Output:
Enter N Limit: 5
15
#include<iostream.h>
#include<conio.h>
int main()
{
int n_limit, result_sum, loop_v;
cout<<"Enter N Limit: ";
cin>>n_limit;
result_sum=0;
for(loop_v=0;loop_v<n_limit;loop_v++);
{
result_sum=result_sum+loop_v;
}
cout<<result_sum;
return 00;
}
Output:
Enter N Limit: 5
15
Subscribe to:
Posts (Atom)