Professional Documents
Culture Documents
struct time t;
fflush(stdout);
cleardevice();
setfillstyle(6,10);
circle(319,239,239);
circle(319,239,219);
floodfill(556,239,15);
setcolor(9);
settextstyle(1,0,4);
outtextxy(301,37,"12");
outtextxy(480,218," 3");
outtextxy(297,400," 6");
outtextxy(113,218," 9");
gettime(&t);
s=t.ti_sec;
h=t.ti_hour;
m=t.ti_min;
int ang=30;
for(int i=0;i<60;i++)
line(320+210*(cos(PI/180*(90-6*i))),240-210*(sin(PI/180*(90-
6*i))),320+200*(cos(PI/180*(90-6*i))),240-200*(sin(PI/180*(90-6*i))));
settextstyle(4,0,3);
outtextxy(263,80,"Neeraj Gulia");
while(1)
{
if (kbhit())
exit(0);
gotoxy(36,25);
printf("%02d::%02d::%02d",h,m,s);
setcolor(4);
xs=320+150*(cos(PI/180*(90-6*s)));
ys=240-150*(sin(PI/180*(90-6*s)));
line(320,240,xs,ys);
setcolor(14);
xm=320+120*(cos(PI/180*(90-6*m)));
ym=240-120*(sin(PI/180*(90-6*m)));
setlinestyle(0,0,3);
line(320,240,xm,ym);
if(s>59)
{
s=0;
m++;
}
setcolor(5);
xh=320+90*(cos(PI/180*(90-ang*h)));
yh=240-90*(sin(PI/180*(90-ang*h)));
line(320,240,xh,yh);
if(m>59)
{
m=0;
h++;
s=0;
}
delay(980);
sound(40);
delay(50);
nosound();
setcolor(0);
line(320,240,xh,yh);
line(320,240,xm,ym);
setlinestyle(0,0,0);
line(320,240,xs,ys);
s++;
}
}
shell sort
#include<iostream.h>
#include<conio.h>
void main()
{
int k,i,temp,n,a[20],swap,gap;
clrscr();
cout<<"enter the no. of elements: ";
cin>>n;
cout<<"enter elements: \n";
for(i=1;i<=n;i++)
cin>>a[i];
gap=n/2;
k=0;
do{
do{
swap=0;
k++;
for(i=1;i<=n-gap;i++)
if(a[i]>a[i+gap])
{
temp=a[i];
a[i]=a[i+gap];
a[i+gap]=temp;
swap=1;
}
}while(swap);
gap=gap/2;
}while(gap);
cout<<"sorted list is: \n";
for(i=1;i<=n;i++)
cout<<a[i]<<endl;
getch();
}
quick sort
#include<iostream.h>
#include<conio.h>
int loc=0;
void main()
{
int i,n,a[20],lower[20],upper[20],top,beg,end;
void quick(int *,int,int,int,int);
clrscr();
cout<<"enter the no. of elements : ";
cin>>n;
cout<<"enter elements: \n";
for(i=1;i<=n;i++)
cin>>a[i];
top=0;
if(n>1)
{
top=top+1;
lower[1]=1;
upper[1]=n;
}
while(top!=0)
{
beg=lower[top];
end=upper[top];
top--;
quick(a,n,beg,end,loc);
if(beg<loc-1)
{
top++;
lower[top]=beg;
upper[top]=loc-1;
}
if(loc+1<end)
{
top++;
lower[top]=loc+1;
upper[top]=end;
}
}
cout<<"sorted list is: \n";
for(i=1;i<=n;i++)
cout<<a[i]<<endl;
}
void main()
{
char *name;
int i;
clrscr();
printf("enter your name: "); // 18
for(i=0;;i++)
{
gotoxy(row,col);
name[i]=getch();
if(name[i]=='\r')
break;
gotoxy(row-i,col);
printf("%s",name);
}
}
#include<stdio.h>
int fib_rec(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return (fib_rec(n - 1) + fib_rec(n - 2));
}
int fib_loop(int n) {
int a, b, sum;
a = b = sum = 0;
b = 1;
if (n <= 0)
return 0;
else if(n == 1 '' n == 2)
return 1;
while(n > 1) {
sum = a + b;
a = b;
b = sum;
n--;
}
return sum;
}
int main() {
int i, n = 37;
printf("the fib upto %d using recursion is: \n",n);
for(i = 0; i < n; i++)
printf("%d, ",fib_loop(i));
puts("");
return 0;
}
C calendar from 1752
#include<stdio.h>
#define Y 1752
// 1/1/1752 Saturday
/* the The calendar as we know it only came into effect (in England) in 1752,
replacing the Julian calendar. Changes included cutting 11 or more days out
of the calendar and changing the first day of the year from march 21st to January 1st,
and so this calculation method should not be used for dates before this changeover.
*/
#define BASE 5
int main() {
char ch = 'y';
int mm,yy,dd;
do {
printf("\nEnter dd ");
scanf("%ld",&dd);
printf("\nEnter mm [1-12] ");
scanf("%ld",&mm);
printf("Enter yyyy ");
scanf("%ld",&yy);
day(dd,mm,yy);
printf("\n\n\n\nPress 'x' to EXIT\n");
fflush(stdin);
ch = getchar();
}while(ch != 'x');
return 0;
}
for(i=Y;i<yy;i++) {
if( (i%4==0) && ((i%100!=0) '' (i%400==0)))
leap++;
}
for(loop=0; loop < track + 2; loop++) /*t+2 due to two additional \t*/
printf("\t");
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
#define PI 3.14
void main(){
int gd=DETECT, gm;
initgraph(&gd, &gm, "\\tc");
int xs, ys, xm, ym, xh, yh, h, m, s;
while(!kbhit()){
cleardevice();
getTime(&h, &m, &s);
settextstyle(1,0,0);
setcolor(WHITE);
outtextxy(300,15,"12");
outtextxy(315,425,"6");
outtextxy(105,220,"9");
outtextxy(520,220,"3");
settextstyle(5,0,0);
setcolor(GREEN);
outtextxy(275,300,"CLOCK");
settextstyle(2 ,0,0);
setcolor(LIGHTRED);
outtextxy(310,295,"Mukesh");
xh = cos((h*30 + m / 2) * PI / 180 - PI / 2) * 150 + 320;
yh = sin((h*30 + m / 2) * PI / 180 - PI / 2) * 150 + 240;
xm = cos(m * PI / 30 - PI / 2) * 180 + 320;
ym = sin(m * PI / 30 - PI / 2) * 180 + 240;
xs = cos(s * PI / 30 - PI / 2) * 210 + 320;
ys = sin(s * PI / 30 - PI / 2) * 210 + 240;
setcolor(LIGHTBLUE);
circle(320,240,220);
setcolor(LIGHTRED);
line(320,240,xh,yh);
setcolor(LIGHTGREEN);
line(320,240,xm,ym);
setcolor(YELLOW);
line(320,240,xs,ys);
sleep(1);
}
}
draw a hut in graphics
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
cleardevice();
fflush(stdout);
line(200,150,350,150);
line(140,200,200,150);
line(140,330,140,200);
line(250,200,140,200);
line(200,150,250,200);
circle(196,180,8);
setfillstyle(2,4);
floodfill(196,180,15);
setfillstyle(1,2);
line(350,150,400,200);
floodfill(210,180,15);
line(400,200,400,330);
line(140,330,400,330);
line(250,200,250,330);
line(250,200,400,200); //hut
setfillstyle(5,7);
floodfill(260,180,15);
line(170,260,170,330);
line(170,260,210,260);
setfillstyle(10,9);
floodfill(180,250,15);
line(210,260,210,330);
setfillstyle(9,9);
floodfill(210,250,15);
line(290,110,290,150);
line(310,110,310,150);
ellipse(300,110,0,360,10,3); //chimney
setfillstyle(6,8);
floodfill(300,120,15);
line(300,250,350,250);
line(300,280,350,280);
line(350,250,350,280);
line(300,280,300,250);
setfillstyle(9,9);
floodfill(252,300,15);
setfillstyle(8,9);
floodfill(342,270,15);
setcolor(4);
settextstyle(7,0,5);
outtextxy(100,390,"Home Sweet Home");
getch();
closegraph();
}
palindrome
int main()
{
int n;
char a[20];
cout<<"enter how many digit string u want 2 enter";
cin>>n;
cout<<"enter the string";
cin>>a;
for(inti=0;i<=n;i++)
{
for(int j=n;j>=0;j--)
if (a[i]==a[j])
s=0;
else
s=1;
}
if(s==0)
cout<<"no.is palindrome ";
else
cout<<"no. is not palindrome";
getch()
return 0;
}
int main(void)
{
char *string = "Borland International";
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
return 0;
}