C Program For Snake Game

#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>

check();
end();
win();
int m[500],n[500],con=20,TEMP;
clock_t start,stop;
                                                                                                                                                                                 void main(void)
{

int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100;
int a=0,i=0,j,t,temp;
initgraph(&gd,&gm,"..//bgi");

setcolor(WHITE);
settextstyle(3,0,6);
outtextxy(200,2,"  ");
settextstyle(6,0,2);
outtextxy(20,80," Use Arrow Keys To Direct The Snake ");
outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of Snake");
outtextxy(20,160," Pick The Beats Untill You Win The Game ");
outtextxy(20,200," Press 'Esc' Anytime To Exit ");
outtextxy(20,220," Press Any Key To Continue ");

outtextxy(20,220," DONT FORGET TO GIVE U R VALUABLE OPINION ");
ch=getch();
if(ch==27) exit(0);
cleardevice();
maxx=getmaxx();
maxy=getmaxy();

randomize();

p=random(maxx);
temp=p%13;
p=p-temp;
q=random(maxy);
temp=q%14;
q=q-temp;



 start=clock();
 while(1)
{

 setcolor(WHITE);
 setfillstyle(SOLID_FILL,con+5);
 circle(p,q,5);
 floodfill(p,q,WHITE);

   if( kbhit() )
   {
     ch=getch(); if(ch==0) ch=getch();
     if(ch==72&& a!=2) a=1;
     if(ch==80&& a!=1) a=2;
     if(ch==75&& a!=4) a=3;
     if(ch==77&& a!=3) a=4;
      }
       else
     {
     if(ch==27
     ) break;
     }

       if(i<20){
           m[i]=x;
           n[i]=y;
           i++;
           }

         if(i>=20)

         {
              for(j=con;j>=0;j--){
                  m[1+j]=m[j];
                  n[1+j]=n[j];
                      }
           m[0]=x;
           n[0]=y;

           setcolor(WHITE);
           setfillstyle(SOLID_FILL,con);
           circle(m[0],n[0],8);
           floodfill(m[0],n[0],WHITE);

           setcolor(WHITE);
           for(j=1;j<con;j++){
          setfillstyle(SOLID_FILL,con+j%3);
           circle(m[j],n[j],5);
           floodfill(m[j],n[j],WHITE);
                      }
       delay(spd);

          setcolor(BLACK);
          setfillstyle(SOLID_FILL,BLACK);
           circle(m[0],n[0],8);
           floodfill(m[0],n[0],BLACK);

           setcolor(BLACK);
          setfillstyle(SOLID_FILL,BLACK);
           circle(m[j],n[j],5);
           floodfill(m[j],n[j],BLACK);

           }
     stop=clock();
     t=(stop-start)/CLK_TCK;
     //printf(" TIME %d sec   ",t);
     //printf("SCORE %d",con-5);
     check();

    if(x==p&&y==q) { con=con+5; if(spd>=5) spd=spd-5; else spd=5;
                       if(con>490) win();
     p=random(maxx); temp=p%13;  p=p-temp;
     q=random(maxy); temp=q%14;   q=q-temp;
                     }
    if(a==1)  y =  y-14; if(y<0) { temp=maxy%14;y=maxy-temp;}
    if(a==2)  y =  y+14; if(y>maxy) y=0;
    if(a==3)  x =  x-13; if(x<0) { temp=maxx%13;x=maxx-temp;}
    if(a==4)  x =  x+13; if(x>maxx) x=0;
    if(a==0){  y = y+14 ;  x=x+13; }
         }

 }


check(){
   int a;
   for(a=1;a<con;a++)

if(m[0]==m[a] && n[0]==n[a]) end();
   else continue;

   }
end()

{

    int j,i;
   setcolor(WHITE);
   for(i=0;i<5;i++){
   delay(500);
    cleardevice();
    delay(500);
   for(j=0;j<=con;j++){
           setfillstyle(SOLID_FILL,RED);
           circle(m[j],n[j],5);
           floodfill(m[j],n[j],WHITE);
          }

         }

    settextstyle(3,0,4);
    outtextxy(150,150,"    GAME OVER ");
    getch();
    getch();
    exit(0);
    }

win()
{
int j,i;
setcolor(WHITE);
   for(i=0;i<5;i++){
   for(j=0;j<=con;j++){
           setfillstyle(SOLID_FILL,con);
           circle(m[j],n[j],5);
           floodfill(m[j],n[j],WHITE);
          }
    delay(500);
    cleardevice();
    delay(500);
         }
  settextstyle(3,0,4);
  outtextxy(210,320," YOU WIN ");
  getch();
  exit(0);
}
Share:

C Program To Find Sum Of Series

#include <stdio.h>
#include <conio.h>
long int factorial(int n);
void main()
{
 int n,i;
 float s,r;
 char c;
 clrscr();
 repeat : printf("\nYou have this series:- 1/1! + 2/2! + 3/3! + 4/4! ...");
 printf("\nTo which term you want its sum?  ");
 scanf("%d",&n);
 s=0;
 for (i=1;i<=n;i++)
  {   s=s+((float)i/(float)factorial(i)); }
 printf("\nThe sum of %d terms is %f",n,s);
 fflush(stdin);
 printf ("\nDo you want to continue?(y/n):-  ");
 scanf("%c",&c);
 if (c=='y')
  goto repeat;
 getch();
}

long int factorial(int n)
 {
  if (n<=1)
    return(1);
  else
    n=n*factorial(n-1);
    return(n);
 }

Sample Output :
You have this series:- 1/1! + 2/2! + 3/3! + 4/4! ...
To which term you want its sum?  15
The sum of 15 terms is 2.709237
Do you want to continue?(y/n):-  n



Share:

Mid Point Circle Algorithm Implementation Using C

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
int midx,midy,i,gdriver = DETECT, gmode,j,x,y,radius,p,xc,yc,x1,y1;
main()
{
initgraph(&gdriver, &gmode, "..//bgi");
setfillstyle(7,8);
bar(0,35,getmaxx(),getmaxy());
settextstyle( 2,0,7);
border();
setcolor(15);
gotoxy(60,14);
outtextxy(80,200,"ENTER THE VALUES OF X-CENTER ");
scanf("%d",&xc);
gotoxy(60,17);
outtextxy(80,250,"ENTER THE VALUES OF Y-CENTER ");
scanf("%d",&xc,&yc);
gotoxy(60,20);
outtextxy(80,300,"ENTER THE RADIUS OF THE CIRCLE ");
scanf("%d",&radius);
setcolor(BLUE);
for(i=0;i<70;i++)
{
setcolor(4);
settextstyle(1,0,3);
outtextxy(50+3*i,10,"MIDPOINT  CIRCLE ALGORITHM");
setcolor((rand()%10)+1);
circle(20+3*i,19,12);
circle(410+3*i,19,12);
delay(7);
setcolor(0);
settextstyle(1,0,3);
outtextxy(50+3*i,10,"MIDPOINT  CIRCLE ALGORITHM");
circle(20+3*i,19,12);
circle(410+3*i,19,12);
settextstyle(1,0,1);
setfillstyle(7,8);
bar(300,450,610,477);
setcolor(rand()%100);
outtextxy(250,410," ");
delay(1);
}
 setfillstyle(7,1);
  bar(0,0,getmaxx(),getmaxy());
  border();
  setcolor(WHITE);
  line(getmaxx()/2,0,getmaxx()/2,getmaxy());
  line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(4);
x=0;
y=radius;
plotpoints();
p=1-radius;
while(x<y)
{
if(p<0)
{
x=x+1;
p=p+(2*x)+1;
}
else
{
x=x+1;
y=y-1;
p=p+2*(x-y)+1;
plotpoints();
}
}
getch();
closegraph();
return 0;
}
plotpoints()
{
putpixel(xc+x+midx,midy-yc+y,15);
putpixel(xc-x+midx,midy-yc+y,15);
putpixel(xc+x+midx,midy-yc-y,15);
putpixel(midx+xc-x,midy-yc-y,15);
putpixel(midx+xc+y,midy-yc+x,15);
putpixel(midx+xc-y,midy-yc+x,15);
putpixel(midx+xc+y,midy-yc-x,15);
putpixel(midx+xc-y,midy-yc-x,15);
}
border()
{
setcolor(5);
rectangle(0,0,getmaxx(),getmaxy());
rectangle(1,1,getmaxx()-1,getmaxy()-1);
rectangle(2,2,getmaxx()-2,getmaxx()-2);
}
Share:

C Graphics Program For Square Animation

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void main()
{
int d=2,k=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\tc\bgi");
setcolor(2);
outtextxy(300,430,"Press any key to continue....");
setcolor(5);
setwritemode(1);
rectangle(180,120,380,320);
getch();
clearviewport();
while(!kbhit())
{
   d%=91;
   setcolor(k);
   rectangle(180+d,120+d,380-d,320-d);
   delay(40);
   d+=2;
    k++;
   }
   getch();
   }


Share:

C Graphics Program To Display Text

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{int i,j,k;
 clrscr();
 printf("        LOOK AT THIS:");
 delay(200);
 clrscr();
for(i=20,j=0;i>=0,j<=4;i--,j++)
 {textcolor(i);
  gotoxy(i,j);
  cprintf("*");
 }//printf("%d %d",wherex(),wherey());
 for(i=16,j=5;i<=30,j<=8;i++,j++)
 {textcolor(i);
  gotoxy(i,j);
  cprintf("*");
 }for(i=16;i<=22;i++)
  {textcolor(i);
   gotoxy(i,5);
   cprintf("*");
   }
  for(j=0;j<=8;j++)
  {gotoxy(23,j);
   textcolor(j);
   cprintf("*");
   }
   for(i=23;i<=25;i++)
   {textcolor(i);
    gotoxy(i,8);
    cprintf("*");
   }
   for(j=8;j<=11;j++)
   {gotoxy(25,j);
    textcolor(j);
    cprintf("*");
    }
    for(i=25;i>=23;i--)
    {gotoxy(i,11);
     textcolor(i);
     cprintf("*");
     }
    for(j=0;j<=6;j++)
    {gotoxy(28,j);
     textcolor(j);
     cprintf("*");
     }
    for(i=28;i<=32;i++)
    {gotoxy(i,6);
     textcolor(i);
     cprintf("*");
    }for(j=0;j<=9;j++)
     {gotoxy(33,j);
      textcolor(j);
      cprintf("*");
     }
     for(j=0;j<=9;j++)
     {gotoxy(37,j);
      textcolor(j);
      cprintf("*");
      }

  while(1)
  {for(i=0;i<=70;i++)
  {gotoxy(i,25);
   sleep(1);
   textcolor(i);
   cprintf(" First Soft");
 }
 }


Share:

C Program To Display Blinking Star

#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
void main()
 {
  int gdriver=DETECT,gmode;
  int i,x,y;
  initgraph(&gdriver,&gmode,"..//bgi");
  while(!kbhit())
   {
    x=random(640);
    y=random(480);
    setcolor(15);
    for(i=1;i<10;i++)
     {
      circle(x,y,i);
      delay(10);
     }
    setfillstyle(1,15);
    line(x+8,y-2,x+40,y);
    line(x+8,y+2,x+40,y);
    floodfill(x+11,y,15);
    line(x-8,y-2,x-40,y);
    line(x-8,y+2,x-40,y);
    floodfill(x-11,y,15);
    line(x-2,y+8,x,y+40);
    line(x+2,y+8,x,y+40);
    floodfill(x,y+11,15);
    line(x-2,y-8,x,y-40);
    line(x+2,y-8,x,y-40);
    floodfill(x,y-11,15);
    line(x+8,y-2,x+20,y-20);
    line(x+2,y-8,x+20,y-20);
    floodfill(x+15,y-15,15);
    line(x+8,y+2,x+20,y+20);
    line(x+2,y+8,x+20,y+20);
    floodfill(x+15,y+15,15);
    line(x-8,y+2,x-20,y+20);
    line(x-2,y+8,x-20,y+20);
    floodfill(x-15,y+15,15);
    line(x-8,y-2,x-20,y-20);
    line(x-2,y-8,x-20,y-20);
    floodfill(x-15,y-15,15);
    sound(4000);
    setcolor(0);
    for(i=40;i>=10;i--)
     {
      line(x+8,y-2,x+i,y);
      line(x+8,y+2,x+i,y);
     }
    for(i=40;i>=10;i--)
     {
      line(x-8,y-2,x-i,y);
      line(x-8,y+2,x-i,y);
     }
    for(i=40;i>=10;i--)
     {
      line(x-2,y+8,x,y+i);
      line(x+2,y+8,x,y+i);
     }
    for(i=40;i>=10;i--)
     {
      line(x-2,y-8,x,y-i);
      line(x+2,y-8,x,y-i);
     }
    for(i=20;i>=7;i--)
     {
      line(x+8,y-2,x+i,y-i);
      line(x+2,y-8,x+i,y-i);
     }
    for(i=20;i>=7;i--)
     {
      line(x+8,y+2,x+i,y+i);
      line(x+2,y+8,x+i,y+i);
     }
    for(i=20;i>=7;i--)
     {
      line(x-8,y+2,x-i,y+i);
      line(x-2,y+8,x-i,y+i);
     }
    for(i=20;i>=7;i--)
     {
      line(x-8,y-2,x-i,y-i);
      line(x-2,y-8,x-i,y-i);
     }
    for(i=9;i>0;i--)
     {
      circle(x,y,i);
      delay(10);
     }
    nosound();
   }
   cleardevice();
   setcolor(2);
   settextstyle(2,0,1);
   outtextxy(220,160," ");
   outtextxy(265,235," ");
   outtextxy(210,335," ");
   getch();getch();
 }
Share:

C Program To Generate Prime Numbers

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int prime(int number, int * primes);

int main(void) {
    int primes[998] = { 3, 0 };
    int n = 5, i;
    int count = 0, found;
    clrscr();
    printf("%8d%8d%8d", 1, 2, 3);               /*  Print first 3 primes     */


    /*  Find the next 997  */

    while ( count < 997 ) {
        i = 0;
        found = 1;


        /*  Test if number divides by any of the primes already found  */

        while ( primes[i] ) {
            if ( (n % primes[i++]) == 0 ) {   /*  If it does...              */
                found = 0;                    /*  ...then it isn't prime...  */
                break;                        /*  ...so stop looking         */
            }
        }

        if ( found ) {
            printf("%8d", n);                /*  If it's prime, print it...  */
            primes[i] =  n;                  /*  ...and add it to the list   */
            ++count;
       
       
            /*  Start a new line every 8 primes found  */
       
            if ( ((count + 3) % 8) == 0 )
                putchar('\n');
        }

    n += 2;
    //getch();    /*  There's no point testing even numbers, so skip them  */
    }

    putchar('\n');
    getch();

    return EXIT_SUCCESS;
}

Sample Output :
      1        2          3        5         7         11       13       17
      19      23       29       31      37         41       43       47
      53      59        61      67      71        73       79       83
      89      97       101     103    107     109     113      127
     131     137     139     149     151     157     63       167
     173     179     181     191    193     197     199      211
     223     227     229     233     239     241     251     257
     263     269     271     277     281     283     293     307
     311     313     317     331     337     347     349     353
     359     367     373     379     383     389     397     401
     409     419     421     431     433     439     443      449
     457     461     463     467     479     487     491     499
     503     509     521     523     541     547     557     563
     569     571     577     587     593     599     601     607
     613     617     619     631     641     643     647     653
     659     661     673     677     683     691     701     709
     719     727     733     739     743     751     757     761
     769     773     787     797     809     811     821     823
     827     829     839     853     857     859     863     877
     881     883     887     907     911     919     929     937
     941     947     953     967     971     977     983     991
     997    1009    1013   1019   1021   1031   1033   1039
    1049   1051   1061    1063   1069   1087   1091   1093
    1097   1103   1109    1117   1123   1129   1151   1153
     .                  .           .           .           .           .           .          
     .                  .           .           .           .           .        7907

Share:

C Program For Accessing Array Elements Using Pointers

#include <stdio.h>
#include <stdlib.h>
#include< conio.h>
int func1();
int func2();
int func3();
int func4();
int func5();

main()
{
    short mat[3][3],i,j;

    for(i = 0 ; i < 3 ; i++)
        for(j = 0 ; j < 3 ; j++)
        {
            mat[i][j] = i*10 + j;
        }

    printf(" Initialized data to: ");
    for(i = 0 ; i < 3 ; i++)
    {
        printf("\n");
        for(j = 0 ; j < 3 ; j++)
        {
            printf("%5.2d", mat[i][j]);
        }
    }
    printf("\n");

    func1(mat);
    func2(mat);
    func3(mat);
    func4(mat);
    func5(mat);
          getch();
}

 /*
 Method #1 (No tricks, just an array with empty first dimension)
 ===============================================================
 You don't have to specify the first dimension!
 */

int func1(short mat[][3])  
{
        register short i, j;

        printf(" Declare as matrix, explicitly specify second dimension: ");
        for(i = 0 ; i < 3 ; i++)
                {
                printf("\n");
                for(j = 0 ; j < 3 ; j++)
                {
                    printf("%5.2d", mat[i][j]);
                }
        }
        printf("\n");

        return;
}

 /*
 Method #2 (pointer to array, second dimension is explicitly specified)
 ======================================================================
 */

int func2(short (*mat)[3])
        {
        register short i, j;

        printf(" Declare as pointer to column, explicitly specify 2nd dim: ");
        for(i = 0 ; i < 3 ; i++)
                {
                printf("\n");
                for(j = 0 ; j < 3 ; j++)
                {
                    printf("%5.2d", mat[i][j]);
                }
        }
        printf("\n");

        return;
}

 /*
 Method #3 (Using a single pointer, the array is "flattened")
 ============================================================
 With this method you can create general-purpose routines.
 The dimensions doesn't appear in any declaration, so you
 can add them to the formal argument list.

 The manual array indexing will probably slow down execution.
 */

int func3(short *mat)   
        {
        register short i, j;

        printf(" Declare as single-pointer, manual offset computation: ");
        for(i = 0 ; i < 3 ; i++)
                {
                printf("\n");
                for(j = 0 ; j < 3 ; j++)
                {
                    printf("%5.2d", *(mat + 3*i + j));
                }
        }
        printf("\n");

        return;
}

 /*
 Method #4 (double pointer, using an auxiliary array of pointers)
 ================================================================
 With this method you can create general-purpose routines,
 if you allocate "index" at run-time.

 Add the dimensions to the formal argument list.
 */

int func4(short **mat)
        {
        short    i, j, *index[3];

        for (i = 0 ; i < 3 ; i++)
                index[i] = (short *)mat + 3*i;

        printf(" Declare as double-pointer, use auxiliary pointer array: ");
        for(i = 0 ; i < 3 ; i++)
                {
                printf("\n");
                for(j = 0 ; j < 3 ; j++)
                {
                    printf("%5.2d", index[i][j]);
                }
        }
        printf("\n");

        return;
}

 /*
 Method #5 (single pointer, using an auxiliary array of pointers)
 ================================================================
 */

int func5(short *mat[3])
        {
        short i, j, *index[3];
        for (i = 0 ; i < 3 ; i++)
                index[i] = (short *)mat + 3*i;

        printf(" Declare as single-pointer, use auxiliary pointer array: ");
        for(i = 0 ; i < 3 ; i++)
                {
                printf("\n");
                for(j = 0 ; j < 3 ; j++)
                {
                    printf("%5.2d", index[i][j]);
                }
        }
        printf("\n");
        return;
}


SAMPLE INPUT AND OUTPUT:

 Initialized data to:
   00   01   02
   10   11   12
   20   21   22
 Declare as matrix, explicitly specify second dimension:
   00   01   02
   10   11   12
   20   21   22
 Declare as pointer to column, explicitly specify 2nd dim:
   00   01   02
   10   11   12
   20   21   22
 Declare as single-pointer, manual offset computation:
   00   01   02
   10   11   12
   20   21   22
 Declare as double-pointer, use auxiliary pointer array:
   00   01   02
   10   11   12
   20   21   22
 Declare as single-pointer, use auxiliary pointer array:
   00   01   02
   10   11   12
   20   21   22
Share:

C Program For Draw Different Kind Of Line

#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>

/* the names of the line styles supported */

char *lname[] = {
   "SOLID_LINE",
   "DOTTED_LINE",
   "CENTER_LINE",
   "DASHED_LINE",
   "USERBIT_LINE"
   };

int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;

   int style, midx, midy, userpat;
   char stylestr[40];

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "..//bgi");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }

   midx = getmaxx() / 2;
   midy = getmaxy() / 2;

   /* a user defined line pattern */
   /* binary: "0000000000000001"  */
   userpat = 1;

   for (style=SOLID_LINE; style<=USERBIT_LINE; style++)
   {
      /* select the line style */
      setlinestyle(style, userpat, 1);

      /* convert style into a string */
      strcpy(stylestr, lname[style]);

      /* draw a line */
      line(0, 0, midx-10, midy);

      /* draw a rectangle */
      rectangle(0, 0, getmaxx(), getmaxy());

      /* output a message */
      outtextxy(midx, midy, stylestr);

      /* wait for a key */
      getch();
      cleardevice();
   }

   /* clean up */
   closegraph();
   return 0;
}
Share:

Simple Animation Program Using C Graphics

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

#define ARROW_SIZE 10

void draw_arrow(int x, int y);

int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;
   void *arrow;
   int x, y, maxx;
   unsigned int size;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "..//bgi");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }

   maxx = getmaxx();
   x = 0;
   y = getmaxy() / 2;

   /* draw the image to be grabbed */
   draw_arrow(x, y);

   /* calculate the size of the image */
   size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);

   /* allocate memory to hold the image */
   arrow = malloc(size);

   /* grab the image */
   getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);

   /* repeat until a key is pressed */
   while (!kbhit())
   {
      /* erase old image */
      putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);

      x += ARROW_SIZE;
      if (x >= maxx)
          x = 0;

      /* plot new image */
      putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
   }

   /* clean up */
   free(arrow);
   closegraph();
   return 0;
}

void draw_arrow(int x, int y)
{
   /* draw an arrow on the screen */
   moveto(x, y);
   linerel(4*ARROW_SIZE, 0);
   linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
   linerel(0, 2*ARROW_SIZE);
   linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
}
Share:

C Program To Create Table and Bar Chart Plot From Set Of Temperature Readings

#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>

/* Prototypes */

void  get_temps(void);
void  table_view(void);
void  min_max(int num_vals, int vals[], int *min_val, int *max_val);
float avg_temp(int num_vals, int vals[]);
void  graph_view(void);
void  save_temps(void);
void  read_temps(void);

/* Global defines */

#define TRUE      1
#define READINGS  8

/* Global data structures */

int  temps[READINGS];

int  main(void)
{
   clrscr();
   while (TRUE)
   {
      printf("\nTemperature Plotting Program Menu\n");
      printf("\tE - Enter temperatures for scratchpad\n");
      printf("\tS - Store scratchpad to disk\n");
      printf("\tR - Read disk file to scratchpad\n");
      printf("\tT - Table view of current data\n");
      printf("\tG - Graph view of current data\n");
      printf("\tX - Exit the program\n");
      printf("\nPress one of the above keys: ");

      switch (toupper(getche()))
      {
     case 'E': get_temps();  break;
     case 'S': save_temps(); break;
     case 'R': read_temps(); break;
     case 'T': table_view(); break;
     case 'G': graph_view(); break;
     case 'X': exit(0);
      }
   }
}

/* Function definitions */
void  get_temps(void)
{
   char inbuf[130];
   int  reading;

   printf("\nEnter temperatures, one at a time.\n");
   for (reading = 0; reading < READINGS; reading++)
   {
      printf("\nEnter reading # %d: ", reading + 1);
      gets(inbuf);
      sscanf(inbuf, "%d", &temps[reading]);
   }
}

void  table_view(void)
{
   int  reading, min, max;

   clrscr();                                /* clear the screen */
   printf("Reading\t\tTemperature(F)\n");

   for (reading = 0; reading < READINGS; reading++)
      printf("%d\t\t\t%d\n", reading + 1, temps[reading]);

   min_max(READINGS, temps, &min, &max);
   printf("Minimum temperature: %d\n", min);
   printf("Maximum temperature: %d\n", max);
   printf("Average temperature: %f\n", avg_temp(READINGS, temps));
}

void  min_max(int num_vals, int vals[], int *min_val, int *max_val)
{
   int  reading;

   *min_val = *max_val = vals[0];

   for (reading = 1; reading < num_vals; reading++)
   {
      if (vals[reading] < *min_val)
         *min_val = vals[reading];
      else if (vals[reading] > *max_val)
         *max_val = vals[reading];
   }
}

float avg_temp(int num_vals, int vals[])
{
   int  reading, total = 0;

   for (reading = 0; reading < num_vals; reading++)
      total += vals[reading];

   return   (float) total/reading;  /* reading equals total vals */
}

void  graph_view(void)
{
   int  graphdriver = DETECT, graphmode;
   int  reading, value;
   int  maxx, maxy, left, top, right, bottom, width;
   int  base;                          /* zero x-axis for graph */
   int  vscale = 1.5;       /* value to scale vertical bar size */
   int  space = 10;                     /* spacing between bars */

   char fprint[20];               /* formatted text for sprintf */

   initgraph(&graphdriver, &graphmode, "..\\bgi");
   if (graphresult() < 0)           /* make sure initialized OK */
      return;

   maxx  = getmaxx();              /* farthest right you can go */
   width = maxx /(READINGS + 1); /* scale and allow for spacing */
   maxy  = getmaxy() - 100;              /* leave room for text */
   left  = 25;
   right = width;
   base  = maxy / 2;              /* allow for neg values below */

   for (reading = 0; reading <  READINGS; reading++)
   {
      value = temps[reading] * vscale;
      if (value > 0)
      {
         top = base - value;            /* toward top of screen */
         bottom = base;
         setfillstyle(HATCH_FILL, 1);
      }
      else
      {
         top = base;
         bottom = base - value;      /* toward bottom of screen */
         setfillstyle(WIDE_DOT_FILL, 2);
      }
      bar(left, top, right, bottom);
      left  +=(width + space);       /* space over for next bar */
      right +=(width + space);        /* right edge of next bar */
   }

   outtextxy(0, base, "0 -");
   outtextxy(10, maxy + 20, "Plot of Temperature Readings");
   for (reading = 0; reading < READINGS; reading++)
   {
      sprintf(fprint, "%d", temps[reading]);
      outtextxy((reading *(width + space)) + 25, maxy + 40, fprint);
   }

   outtextxy(50, maxy+80, "Press any key to continue");

   getch();                               /* Wait for a key press */

   closegraph();
}

void  save_temps(void)
{
   FILE * outfile;
   char file_name[40];

   printf("\nSave to what filename? ");
   while (kbhit());  /* "eat" any char already in keyboard buffer */
   gets(file_name);

   if ((outfile = fopen(file_name,"wb")) == NULL)
   {
      perror("\nOpen failed! ");
      return;
   }
   fwrite(temps, sizeof(int), READINGS, outfile);
   fclose(outfile);
}

void  read_temps(void)
{
   FILE * infile;
   char file_name[40] = "test";

   printf("\nRead from which file? ");
   while (kbhit());  /* "eat" any char already in keyboard buffer */
   gets(file_name);

   if ((infile = fopen(file_name,"rb")) == NULL)
   {
      perror("\nOpen failed! ");
      return;
   }
   fread(temps, sizeof(int), READINGS, infile);
   fclose(infile);
}

Sample Input :
Temperature Plotting Program Menu
        E - Enter temperatures for scratchpad
        S - Store scratchpad to disk
        R - Read disk file to scratchpad
        T - Table view of current data
        G - Graph view of current data
        X - Exit the program
Press one of the above keys: E


Share:

C Program To Display Circles

#include <graphics.h>           /* For graphics library functions */
#include <stdlib.h>             /* For exit() */
#include <stdio.h>
#include <conio.h>

int set_graph(void);            /* Initialize graphics */
void calc_coords(void);         /* Scale distances onscreen */
void draw_planets(void);        /* Draw and fill planet circles */

/* Draw one planet circle */
void draw_planet(float x_pos, float radius,
                 int color, int fill_style);
void get_key(void);         /* Display text on graphics screen, */
                            /* wait for key */

/* Global variables -- set by calc_coords() */
int max_x, max_y;           /* Maximum x- and y-coordinates */
int y_org;                  /* Y-coordinate for all drawings */
int au1;                    /* One astronomical unit in pixels
                               (inner planets) */
int au2;                    /* One astronomical unit in pixels
                               (outer planets) */
int erad;                   /* One earth radius in pixels */

int main()
{
   /* Exit if not EGA or VGA */
   /* Find out if they have what it takes */
   if (set_graph() != 1) {
      printf("This program requires EGA or VGA graphics\n");
      exit(0);
   }
   calc_coords();       /* Scale to graphics resolution in use */
   draw_planets();      /* Sun through Uranus (no room for others) */
   get_key();           /* Display message and wait for key press */
   closegraph();        /* Close graphics system */

   return 0;
}

int set_graph(void)
{
   int graphdriver = DETECT, graphmode, error_code;

   /* Initialize graphics system; must be EGA or VGA */
   initgraph(&graphdriver, &graphmode, "..\\bgi");
   error_code = graphresult();
   if (error_code != grOk)
      return(-1);               /* No graphics hardware found */
   if ((graphdriver != EGA) && (graphdriver != VGA))
   {
      closegraph();
      return 0;
   }
   return(1);                   /* Graphics OK, so return "true" */
}

void calc_coords(void)
{
   /* Set global variables for drawing */
   max_x = getmaxx();           /* Returns maximum x-coordinate */
   max_y = getmaxy();           /* Returns maximum y-coordinate */
   y_org = max_y / 2;           /* Set Y coord for all objects */
   erad = max_x  / 200;         /* One earth radius in pixels */
   au1 = erad * 20;             /* Scale for inner planets */
   au2 = erad * 10;             /* scale for outer planets */
}

void draw_planets()
{
   /* Each call specifies x-coordinate in au, radius, and color */
   /* arc of Sun */
   draw_planet(-90, 100, EGA_YELLOW, EMPTY_FILL);
   /* Mercury */
   draw_planet(0.4 * au1, 0.4 * erad, EGA_BROWN, LTBKSLASH_FILL);
   /* Venus */
   draw_planet(0.7 * au1, 1.0 * erad, EGA_WHITE, SOLID_FILL);
   /* Earth */
   draw_planet(1.0 * au1, 1.0 * erad, EGA_LIGHTBLUE, SOLID_FILL);
   /* Mars */
   draw_planet(1.5 * au1, 0.4 * erad, EGA_LIGHTRED, CLOSE_DOT_FILL);
   /* Jupiter */
   draw_planet(5.2 * au2, 11.2 * erad, EGA_WHITE, LINE_FILL);
   /* Saturn */
   draw_planet(9.5 * au2, 9.4 * erad, EGA_LIGHTGREEN, LINE_FILL);
   /* Uranus */
   draw_planet(19.2 * au2, 4.2 * erad, EGA_GREEN, LINE_FILL);
}

void draw_planet(float x_pos, float radius, int color, int fill_style)
{
   setcolor (color);                /* This becomes drawing color */
   circle(x_pos, y_org, radius);    /* Draw the circle */
   setfillstyle(fill_style, color); /* Set pattern to fill interior */
   floodfill(x_pos, y_org, color);  /* Fill the circle */
}

void get_key(void)
{
   outtextxy(50, max_y - 20, "Press any key to exit");
   getch();
}


Share:

C Program To Display Barchart

#include           <stdio.h>
#include           <stdlib.h>
#include           <float.h>
#include           <graphics.h>
#include           <math.h>
#include           <conio.h>
#define            MAX        50
#define            SIZE   5

void barchart(float p[]);

void main(void)
{
  int              i;
  int              scores[SIZE];
  float            percents[SIZE];

  for (i = 0; i < SIZE; i++)
    {
    printf("\nEnter score between 0 and %d:  ", MAX);
    scanf("%d", &scores[i]);
    }
  for (i = 0; i < SIZE; i++)
    percents[i] = ((float) scores[i]) / MAX;

  printf("\n\n\n\tSCORE\tPERCENT");
  for (i = 0; i < SIZE; i++)
    printf("\n%d. \t%d\t%3.0f", i + 1, scores[i], (percents[i] * 100));
  getch();
  barchart(percents);
}

void barchart(float p[])
{
  int   g_driver, g_mode;
  int   i, left, top, wide, bottom, deep;
  detectgraph(&g_driver, &g_mode);
  initgraph(&g_driver, &g_mode, "..\\bgi");
  wide = (int)((getmaxx()) / ((SIZE * 2 ) + 1));
  bottom = getmaxy() - 20;
  deep = (int) (wide / 4);
  left = wide;
  for (i = 0; i < SIZE; i++)
    {
    top = (bottom) - ((int)(p[i] * 300));
    setcolor(5);
    bar3d(left, top, (left + wide), bottom, deep, 1);
    left += (wide * 2);
    }
  getch();
  closegraph();
  return;
}

Sample Input :
Enter score between 0 and 50:  5
Enter score between 0 and 50:  6
Enter score between 0 and 50:  45
Enter score between 0 and 50:  3
Enter score between 0 and 50:  1

        SCORE   PERCENT
1.      5        10
2.      6        12
3.      45       90
4.      3         6
5.      1         2

Share:

C Program To Copy One Array Elements into Another Array in Desired Position

Algorithm Steps:
Step 1: Create Two arrays with same size.

Step 2: Read the Array elements using the function getIntArray.

Step 3: Print the Array using printIntArray.

Step 4: Copy the Array using function cpIntArray.

Step 5: Print the Array using cpIntArray.  

 #include <stdio.h>
#define SIZE 8

void cpIntArray(int *a, int *b, int n)

/*It copies n integers starting at b into a*/

{
  for(;n>0;n--)
    *a++=*b++;
}


void printIntArray(int a[], int n)
     /* n is the number of elements in the array a.
      * These values are printed out, five per line. */
{
  int i;

  for (i=0; i<n; ){
    printf("\t%d ", a[i++]);
    if (i%5==0)
      printf("\n");
  }
  printf("\n");
}

/* It reads up to nmax integers and stores then in a; sentinel
      * terminates input. */
int getIntArray(int a[], int nmax, int sentinel)
 {
          int n = 0;
         int temp;
    do {
        printf("Enter integer [%d to terminate] : ", sentinel);
                 scanf("%d", &temp);
                if (temp==sentinel) break;
               if (n==nmax)
               printf("array is full\n");
           else
                a[n++] = temp;
        }while (1);
        return n;
}

int main(void)
{
       int x[SIZE], nx;
     int y[SIZE], ny;
                   printf("Read the x array:\n");
     nx = getIntArray(x,SIZE,0);
                  printf("The x array is:\n");
                 printIntArray(x,nx);
                printf("Read the y array:\n");
               ny = getIntArray(y,SIZE,0);
              printf("The y array is:\n");
              printIntArray(y,ny);
             cpIntArray(x+2,y+3,4);
  /*Notice the expression 'x+2'. x is interpreted as the address for
    the beginning of the x array. +2 sais to increment that address
    by two units, in accordance with the type of x, which is
    an integer array. Thus we move from x to two integer locations
    past it, that is to the location of x[2]. The same reasoning applied
    to 'y+3'.
    */
  printf("Printing x after having copied 4 elements\n"
         "from y starting at y[3] into x starting at x[2]\n");
  printIntArray(x,nx);
}

Sample Output :
Read the x array:
Enter integer [0 to terminate] : 1
Enter integer [0 to terminate] : 3
Enter integer [0 to terminate] : 5
Enter integer [0 to terminate] : 7
Enter integer [0 to terminate] : 9
Enter integer [0 to terminate] : 11
Enter integer [0 to terminate] : 13
Enter integer [0 to terminate] : 15
Enter integer [0 to terminate] : 0
The x array is:
            1          3          5          7          9
            11        13        15
Read the y array:
Enter integer [0 to terminate] : 2
Enter integer [0 to terminate] : 4
Enter integer [0 to terminate] : 6
Enter integer [0 to terminate] : 8
Enter integer [0 to terminate] : 10
Enter integer [0 to terminate] : 12
Enter integer [0 to terminate] : 14
Enter integer [0 to terminate] : 16
Enter integer [0 to terminate] : 0
The y array is:
            2          4          6          8          10
            12        14        16
Printing x after having copied 4 elements
from y starting at y[3] into x starting at x[2]
            1          3          8          10        12
            14        13        15
Share:

Image Watermarking Using Combined DWT and DCT Full Matlab Project With Source Code

ABSTRACT
                  The authenticity & copyright protection are two major problems in handling digital multimedia. The Image watermarking is most popular method for copyright protection by discrete Wavelet Transform (DWT) which performs 2 Level Decomposition of original (cover) image and watermark image is embedded in Lowest Level (LL) sub band of cover image. Inverse Discrete Wavelet Transform (IDWT) is used to recover original image from watermarked image. And Discrete Cosine Transform (DCT) which convert image into Blocks of M bits and then reconstruct using IDCT. In this paper we have compared watermarking using DWT & DWT-DCT methods performance analysis on basis of PSNR, Similarity factor of watermark and recovered watermark.

PROJECT OUTPUT

PROJECT VIDEO

Contact:  
Mr. Roshan P. Helonde
Mobile / WhatsApp:+91-7276355704
Share:

Vehicle License Number Plate Recognition Using Image Processing Full Matlab Project With Source Code

ABSTRACT
                The road becomes more pervasive, our country's road transport development, because of rapid labor management has not filled with actual needs, microelectronics, communications and computer technology in the transport sector of the application has greatly improved the traffic management efficiency. car license plates for automatic identification technology has been widely applied. car license plates automatically identify the entire process is divided into pre-processing, edge extraction, License Plate Positioning, character segmentation and character recognition 5 module, which character recognition process mainly consists of the following three components: 1) correctly to split text image area; 2) correct separation of a single text; 3) correctly identify a single character. The MATLAB software programming to achieve each and every part, and finally identify the license plate of a car. In the study of the same in which the issue of a concrete analysis, and processing. vehicle license plate recognition system as a whole is the main vehicle positioning and character recognition made up of two parts, one license plate positioning and can be divided into image pre-processing and edge extraction module and the licensing of the positioning and segmentation module; character recognition can be divided into character segmentation and feature extraction and a single character recognition two modules.

PROJECT OUTPUT

PROJECT VIDEO


Contact:  
Mr. Roshan P. Helonde
Mobile / WhatsApp:+91-7276355704
Share:

Tcl script to draw the graph and set x and y coordinates randomly NS2 WIRELESS PROGRAM

Description:

     X, Y coordinates for the graph is generated randomly and put it in a trace file. The trace file is given as input file to xgraph to plot the graph.

File name: “graph1.tcl”
# Creating simulation
set ns [new Simulator]

#Creating nam and trace file
set tracefd       [open Graph1.tr w]
set namtrace      [open Graph1.nam w]  

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

set god_ [create-god $val(nn)]

# configure the nodes
        $ns node-config -adhocRouting $val(rp) \
                   -llType $val(ll) \
                   -macType $val(mac) \
                   -ifqType $val(ifq) \
                   -ifqLen $val(ifqlen) \
                   -antType $val(ant) \
                   -propType $val(prop) \
                   -phyType $val(netif) \
                   -channelType $val(chan) \
                   -topoInstance $topo \
                   -agentTrace ON \
                   -routerTrace ON \
                   -macTrace OFF \
                   -movementTrace ON
                  
## Creating node objects..        
for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]    
      }
      for {set i 0} {$i < $val(nn)  } {incr i } {
            $node_($i) color black
            $ns at 0.0 "$node_($i) color black"
      }

# Provide initial location of mobilenodes
$node_(0) set X_ 50.0
$node_(0) set Y_ 50.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0
$node_(1) set Y_ 250.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 300.0
$node_(2) set Y_ 300.0
$node_(2) set Z_ 0.0

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 10.01 "puts \"end simulation\" ; $ns halt"

#Graph procedure..
$ns at 1.0 "Graph"
set g [open graph.tr w]
proc Graph {} {
global ns g
set time 1.0
set now [$ns now]
puts $g "[expr rand()*8] [expr rand()*6]"

$ns at [expr $now+$time] "Graph"
}

#Stop proceture
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
exec xgraph -M -bb -geometry 700X800 graph.tr &
exec nam Graph1.nam &
exit 0
}

$ns run

# How to run the program

$ns Graph1.tcl

# snapshot of the program output

Share:

Tcl script to make TCP communication between nodes using DSDV routing protocol NS2 WIRELESS PROGRAM

Description:

      Number of nodes (3) is fixed in the program. Nodes are configured with specific parameters of a mobile wireless node. After creating the nam file and trace file, we set up topography object. set node_ ($i) [$ns node] is used to create the nodes. Initial location of the nodes is fixed. Specific X, Y coordinates are assigned to every node. Nodes are given mobility with fixed speed and fixed destination location. Here we set the initial size for the every node by using initial_node_pos. DSDV routing protocol is used here. $val(stop) specifies the end time of the simulation. TCP agent is attached to node_ (0). TCPSink agent is attached to node_(1). Both the agents are connected and FTP application is attached to TCP agent. Now communication set up for node_(0) and node_(1) is established.

File name: “dsdv.tcl”
#Creating trace file and nam file
set tracefd       [open dsdv.tr w]
set windowVsTime2 [open win.tr w]
set namtrace      [open dsdv.nam w]  

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes
        $ns node-config -adhocRouting $val(rp) \
                   -llType $val(ll) \
                   -macType $val(mac) \
                   -ifqType $val(ifq) \
                   -ifqLen $val(ifqlen) \
                   -antType $val(ant) \
                   -propType $val(prop) \
                   -phyType $val(netif) \
                   -channelType $val(chan) \
                   -topoInstance $topo \
                   -agentTrace ON \
                   -routerTrace ON \
                   -macTrace OFF \
                   -movementTrace ON
                  
      for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]    
      }

# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 490.0
$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
exec nam dsdv.nam &
exit 0
}

$ns run

# How to run the program:

$ns dsdv.tcls

#snapshot of the program:

Share:

Tcl script to make communication between nodes using AODV routing protocol and CBR traffic NS2 WIRELESS PROGRAM

Description:

     Number of nodes (22) is fixed in the program. Nodes are configured with specific parameters of a mobile wireless node. After creating the nam file and trace file, we set up topography object. set node_ ($i) [$ns node] is used to create the nodes. Initial location of the nodes is fixed. Specific X, Y coordinates are assigned to every node. Nodes are given mobility with fixed speed and fixed destination location. Here we set the initial size for the every node by using initial_node_pos. AODV routing protocol is used here. $val(stop) specifies the end time of the simulation. UDP agent is attached to sender node. LossMonitor agent is attached to receiver node. Both the agents are connected and CBR traffic is attached to UDP agent. Now communication set up for nodes are established.

File name: “Aodv.tcl”

### Setting The Simulator Objects
                 
      set ns_ [new Simulator]
#create the nam and trace file:
      set tracefd [open aodv.tr w]
      $ns_ trace-all $tracefd

      set namtrace [open aodv.nam w]
      $ns_ namtrace-all-wireless $namtrace  $val(x) $val(y)
      set topo [new Topography]
      $topo load_flatgrid $val(x) $val(y)
      create-god $val(nn)
      set chan_1_ [new $val(chan)]
     
####  Setting The Distance Variables
                      
      # For model 'TwoRayGround'
      set dist(5m)  7.69113e-06
      set dist(9m)  2.37381e-06
      set dist(10m) 1.92278e-06
      set dist(11m) 1.58908e-06
      set dist(12m) 1.33527e-06
      set dist(13m) 1.13774e-06
      set dist(14m) 9.81011e-07
      set dist(15m) 8.54570e-07
      set dist(16m) 7.51087e-07
      set dist(20m) 4.80696e-07
      set dist(25m) 3.07645e-07
      set dist(30m) 2.13643e-07
      set dist(35m) 1.56962e-07
      set dist(40m) 1.56962e-10
      set dist(45m) 1.56962e-11
      set dist(50m) 1.20174e-13
      Phy/WirelessPhy set CSThresh_ $dist(50m)
      Phy/WirelessPhy set RXThresh_ $dist(50m)
#  Defining Node Configuration
                       
                  $ns_ node-config -adhocRouting $val(rp) \
                   -llType $val(ll) \
                   -macType $val(mac) \
                   -ifqType $val(ifq) \
                   -ifqLen $val(ifqlen) \
                   -antType $val(ant) \
                   -propType $val(prop) \
                   -phyType $val(netif) \
                   -topoInstance $topo \
                   -agentTrace ON \
                   -routerTrace ON \
                   -macTrace ON \
                   -movementTrace ON \
                   -channel $chan_1_
###  Creating The WIRELESS NODES
                 
      set Server1 [$ns_ node]
      set Server2 [$ns_ node]
      set n2 [$ns_ node]
      set n3 [$ns_ node]
      set n4 [$ns_ node]
      set n5 [$ns_ node]
      set n6 [$ns_ node]
      set n7 [$ns_ node]
      set n8 [$ns_ node]
      set n9 [$ns_ node]
      set n10 [$ns_ node]
      set n11 [$ns_ node]
      set n12 [$ns_ node]
      set n13 [$ns_ node]
      set n14 [$ns_ node]
      set n15 [$ns_ node]
      set n16 [$ns_ node]
      set n17 [$ns_ node]
      set n18 [$ns_ node]
      set n19 [$ns_ node]
      set n20 [$ns_ node]
      set n21 [$ns_ node]
      set n22 [$ns_ node]
     
      set opt(seed) 0.1
      set a [ns-random $opt(seed)]
      set i 0
      while {$i < 5} {
      incr i
      }
           
###  Setting The Initial Positions of Nodes
      $Server1 set X_ 513.0
      $Server1 set Y_ 517.0
      $Server1 set Z_ 0.0
     
      $Server2 set X_ 1445.0
      $Server2 set Y_ 474.0
      $Server2 set Z_ 0.0
     
      $n2 set X_ 36.0
      $n2 set Y_ 529.0
      $n2 set Z_ 0.0
      $n3 set X_ 143.0
      $n3 set Y_ 666.0
      $n3 set Z_ 0.0
      $n4 set X_ 201.0
      $n4 set Y_ 552.0
      $n4 set Z_ 0.0
     
      $n5 set X_ 147.0
      $n5 set Y_ 403.0
      $n5 set Z_ 0.0
     
      $n6 set X_ 230.0
      $n6 set Y_ 291.0
      $n6 set Z_ 0.0
      $n7 set X_ 295.0
      $n7 set Y_ 419.0
      $n7 set Z_ 0.0
      $n8 set X_ 363.0
      $n8 set Y_ 335.0
      $n8 set Z_ 0.0
      $n9 set X_ 334.0
      $n9 set Y_ 647.0
      $n9 set Z_ 0.0
      $n10 set X_ 304.0
      $n10 set Y_ 777.0
      $n10 set Z_ 0.0
     
      $n11 set X_ 412.0
      $n11 set Y_ 194.0
      $n11 set Z_ 0.0
     
      $n12 set X_ 519.0
      $n12 set Y_ 361.0
      $n12 set Z_ 0.0
      $n13 set X_ 569.0
      $n13 set Y_ 167.0
      $n13 set Z_ 0.0
      $n14 set X_ 349.0
      $n14 set Y_ 546.0
      $n14 set Z_ 0.0
      $n15 set X_ 466.0
      $n15 set Y_ 668.0
      $n15 set Z_ 0.0
      $n16 set X_ 489.0
      $n16 set Y_ 794.0
      $n16 set Z_ 0.0
      $n17 set X_ 606.0
      $n17 set Y_ 711.0
      $n17 set Z_ 0.0
      $n18 set X_ 630.0
      $n18 set Y_ 626.0
      $n18 set Z_ 0.0
      $n19 set X_ 666.0
      $n19 set Y_ 347.0
      $n19 set Z_ 0.0
      $n20 set X_ 741.0
      $n20 set Y_ 152.0
      $n20 set Z_ 0.0
      $n21 set X_ 882.0
      $n21 set Y_ 264.0
      $n21 set Z_ 0.0
     
      $n22 set X_ 761.0
      $n22 set Y_ 441.0
      $n22 set Z_ 0.0
     
      ## Giving Mobility to Nodes
     
      $ns_ at 0.75 "$n2 setdest 379.0 349.0 20.0"
      $ns_ at 0.75 "$n3 setdest 556.0 302.0 20.0"
      $ns_ at 0.20 "$n4 setdest 309.0 211.0 20.0"
      $ns_ at 1.25 "$n5 setdest 179.0 333.0 20.0"
      $ns_ at 0.75 "$n6 setdest 139.0 63.0 20.0"
      $ns_ at 0.75 "$n7 setdest 320.0 27.0 20.0"
      $ns_ at 1.50 "$n8 setdest 505.0 124.0 20.0"
      $ns_ at 1.25 "$n9 setdest 274.0 487.0 20.0"
      $ns_ at 1.25 "$n10 setdest 494.0 475.0 20.0"
      $ns_ at 1.25 "$n11 setdest 899.0 757.0 25.0"
      $ns_ at 0.50 "$n12 setdest 598.0 728.0 25.0"
      $ns_ at 0.25 "$n13 setdest 551.0 624.0 25.0"
      $ns_ at 1.25 "$n14 setdest 397.0 647.0 25.0"
      $ns_ at 1.25 "$n15 setdest 748.0 688.0 25.0"
      $ns_ at 1.25 "$n16 setdest 842.0 623.0 25.0"
      $ns_ at 1.25 "$n17 setdest 678.0 548.0 25.0"
      $ns_ at 0.75 "$n18 setdest 741.0 809.0 20.0"
      $ns_ at 0.75 "$n19 setdest 437.0 799.0 20.0"
      $ns_ at 0.20 "$n20 setdest 159.0 722.0 20.0"
      $ns_ at 1.25 "$n21 setdest 700.0 350.0 20.0"
      $ns_ at 0.75 "$n22 setdest 839.0 444.0 20.0"
           
      ## Setting The Node Size
                             
      $ns_ initial_node_pos $Server1 75
      $ns_ initial_node_pos $Server2 75
      $ns_ initial_node_pos $n2 40
      $ns_ initial_node_pos $n3 40
      $ns_ initial_node_pos $n4 40
      $ns_ initial_node_pos $n5 40
      $ns_ initial_node_pos $n6 40
      $ns_ initial_node_pos $n7 40
      $ns_ initial_node_pos $n8 40
      $ns_ initial_node_pos $n9 40
      $ns_ initial_node_pos $n10 40
      $ns_ initial_node_pos $n11 40
      $ns_ initial_node_pos $n12 40
      $ns_ initial_node_pos $n13 40
      $ns_ initial_node_pos $n14 40
      $ns_ initial_node_pos $n15 40
      $ns_ initial_node_pos $n16 40
      $ns_ initial_node_pos $n17 40
      $ns_ initial_node_pos $n18 40
      $ns_ initial_node_pos $n19 40
      $ns_ initial_node_pos $n20 40
      $ns_ initial_node_pos $n21 40
      $ns_ initial_node_pos $n22 40
     
      #### Setting The Labels For Nodes
     
      $ns_ at 0.0 "$Server1 label Server1"
      $ns_ at 0.0 "$Server2 label Server2"
     
      #Setting Color For Server
     
      $Server1 color maroon
      $ns_ at 0.0 "$Server1 color maroon"
     
      $Server2 color maroon
      $ns_ at 0.0 "$Server2 color maroon"
      ## SETTING ANIMATION RATE
$ns_ at 0.0 "$ns_ set-animation-rate 15.0ms"
   #  COLORING THE NODES 
$n9 color blue
$ns_ at 4.71 "$n9 color blue"
$n5 color blue
$ns_ at 7.0 "$n5 color blue"
$n2 color blue
$ns_ at 7.29 "$n2 color blue"
$n16 color blue
$ns_ at 7.59 "$n16 color blue"
$n9 color maroon
$ns_ at 7.44 "$n9 color maroon"
$ns_ at 7.43 "$n9 label TTLover"
$ns_ at 7.55 "$n9 label \"\""
$n12 color blue
$ns_ at 7.85 "$n12 color blue"
                 
####  Establishing Communication
      set udp0 [$ns_ create-connection UDP $Server1 LossMonitor $n18 0]
      $udp0 set fid_ 1
      set cbr0 [$udp0 attach-app Traffic/CBR]
      $cbr0 set packetSize_ 1000   
      $cbr0 set interval_ .07
      $ns_ at 0.0 "$cbr0 start"
      $ns_ at 4.0 "$cbr0 stop"
     
      set udp1 [$ns_ create-connection UDP $Server1 LossMonitor $n22 0]
      $udp1 set fid_ 1
      set cbr1 [$udp1 attach-app Traffic/CBR]
      $cbr1 set packetSize_ 1000   
      $cbr1 set interval_ .07
      $ns_ at 0.1 "$cbr1 start"
      $ns_ at 4.1 "$cbr1 stop"
     
     
      set udp2 [$ns_ create-connection UDP $n21 LossMonitor $n20 0]
      $udp2 set fid_ 1
      set cbr2 [$udp2 attach-app Traffic/CBR]
      $cbr2 set packetSize_ 1000   
      $cbr2 set interval_ .07
      $ns_ at 2.4 "$cbr2 start"
      $ns_ at 4.1 "$cbr2 stop"
     
      set udp3 [$ns_ create-connection UDP $Server1 LossMonitor $n15 0]
      $udp3 set fid_ 1
      set cbr3 [$udp3 attach-app Traffic/CBR]
      $cbr3 set packetSize_ 1000   
      $cbr3 set interval_ 5
      $ns_ at 4.0 "$cbr3 start"
      $ns_ at 4.1 "$cbr3 stop"
     
      set udp4 [$ns_ create-connection UDP $Server1 LossMonitor $n14 0]
      $udp4 set fid_ 1
      set cbr4 [$udp4 attach-app Traffic/CBR]
      $cbr4 set packetSize_ 1000   
      $cbr4 set interval_ 5
      $ns_ at 4.0 "$cbr4 start"
      $ns_ at 4.1 "$cbr4 stop"
     
      set udp5 [$ns_ create-connection UDP $n15 LossMonitor $n16 0]
      $udp5 set fid_ 1
      set cbr5 [$udp5 attach-app Traffic/CBR]
      $cbr5 set packetSize_ 1000   
      $cbr5 set interval_ 5
      $ns_ at 4.0 "$cbr5 start"
      $ns_ at 4.1 "$cbr5 stop"
     
      set udp6 [$ns_ create-connection UDP $n15 LossMonitor $n17 0]
      $udp6 set fid_ 1
      set cbr6 [$udp6 attach-app Traffic/CBR]
      $cbr6 set packetSize_ 1000   
      $cbr6 set interval_ 5
      $ns_ at 4.0 "$cbr6 start"
      $ns_ at 4.1 "$cbr6 stop"
           
      set udp7 [$ns_ create-connection UDP $n14 LossMonitor $n4 0]
      $udp7 set fid_ 1
      set cbr7 [$udp7 attach-app Traffic/CBR]
      $cbr7 set packetSize_ 1000   
      $cbr7 set interval_ 5
      $ns_ at 4.0 "$cbr7 start"
      $ns_ at 4.1 "$cbr7 stop"
     
      set udp8 [$ns_ create-connection UDP $n14 LossMonitor $n9 0]
      $udp8 set fid_ 1
      set cbr8 [$udp8 attach-app Traffic/CBR]
      $cbr8 set packetSize_ 1000   
      $cbr8 set interval_ 5
      $ns_ at 4.0 "$cbr8 start"
      $ns_ at 4.1 "$cbr8 stop"
     
      set udp9 [$ns_ create-connection UDP $n4 LossMonitor $n3 0]
      $udp9 set fid_ 1
      set cbr9 [$udp9 attach-app Traffic/CBR]
      $cbr9 set packetSize_ 1000   
      $cbr9 set interval_ 5
      $ns_ at 4.0 "$cbr9 start"
      $ns_ at 4.1 "$cbr9 stop"
     
      set udp10 [$ns_ create-connection UDP $n4 LossMonitor $n2 0]
      $udp10 set fid_ 1
      set cbr10 [$udp10 attach-app Traffic/CBR]
      $cbr10 set packetSize_ 1000  
      $cbr10 set interval_ 5
      $ns_ at 4.0 "$cbr10 start"
      $ns_ at 4.1 "$cbr10 stop"
     
      set udp11 [$ns_ create-connection UDP $n9 LossMonitor $n16 0]
      $udp11 set fid_ 1
      set cbr11 [$udp11 attach-app Traffic/CBR]
      $cbr11 set packetSize_ 1000  
      $cbr11 set interval_ 5
      $ns_ at 4.0 "$cbr11 start"
      $ns_ at 4.1 "$cbr11 stop"
     
      set udp12 [$ns_ create-connection UDP $n9 LossMonitor $n10 0]
      $udp12 set fid_ 1
      set cbr12 [$udp12 attach-app Traffic/CBR]
      $cbr12 set packetSize_ 1000  
      $cbr12 set interval_ 5
      $ns_ at 4.0 "$cbr12 start"
      $ns_ at 4.1 "$cbr12 stop"
      #ANNOTATIONS DETAILS
      $ns_ at 0.0 "$ns_ trace-annotate \"MOBILE NODE MOVEMENTS\""
      $ns_ at 4.1 "$ns_ trace-annotate \"NODE27 CACHE THE DATA FRO SERVER\""
      #$ns_ at 4.59 "$ns_ trace-annotate \"PACKET LOSS AT NODE27\""    
      $ns_ at 4.71 "$ns_ trace-annotate \"NODE10 CACHE THE DATA\""     
           
      ### PROCEDURE TO STOP
      proc stop {} {
           
                        global ns_ tracefd
                        $ns_ flush-trace
                        close $tracefd
                        exec nam datacache.nam &           
                        exit 0
                   }
      puts "Starting Simulation........"
      $ns_ at 25.0 "stop"
      $ns_ run
          
# How to run the program:
$ns aodv1.tcl
#snapshot of the program:
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *