Amazon banner

Sunday, 16 September 2012

PROGRAM TO GENERATE IP ADDRESSES


/***********************************************************************/
/* PROGRAM TO GENERATE IP ADDRESSES                                    */
/* AUTHOR : DEEPAK MAHAKALE 3 YEAR IT SRCOEM                           */
/* BLOG : www.mahakaledeepak.blogspot.com                              */
/***********************************************************************/
#include<stdio.h>
#include<conio.h>
void main() {
  int n1, n2, n3, n4, i, j, k, l, m, cnt = 0, a[50];
  clrscr();
  printf("\n\t* IP ADDRESSES ALLOTTED TO RCOEM * ");

  for (i = 5; i < 50; i++) {
    n1 = i;
    for (j = 1; j < 255; j++) {
      n2 = j;
      for (k = 5; k < 50; k++) {
        n3 = k;
        for (l = 1; l < 255; l++) {
          n4 = l;
          if (n1 + n3 <= 50) {
            if (n1 % n4 == 0 && n3 % n4 == 0) {
              m = 1;
              a[3] = 1000, cnt = 0;
              while (m < 10) {
                if (n4 % m == 0) {
                  a[++cnt] = m;
                }
                m++;
              }
              if (n2 == a[3] && n2 != n4) {
                {
                  printf("\n\t %d.%d.%d.%d", n1, n2, n3, n4);
                }
              }
            }
          }
        }
      }
    }
  }
  getch();
}

PROGRAM TO DETECT WHETHER ENTERED NUMBER IS DIVISIBLE BY 11


/***********************************************************************/
/* PROGRAM TO DETECT WHETHER ENTERED NUMBER IS DIVISIBLE BY 11         */
/* AUTHOR : DEEPAK MAHAKALE 3 YEAR IT SRCOEM                           */
/* BLOG : www.mahakaledeepak.blogspot.com                   */
/***********************************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{

    long int r=0,i=1,odd=0,even=0,no,n,rev=0;
    clrscr();
    printf("\n\t PROGRAM TO DETECT WHETHER ENTERED NUMBER IS DIVISIBLE BY 11 ");
    printf("\n\n\t Enter any number : ");
    scanf("%ld",&n);
    no=n;

        while(no!=0)
       {
          
           r=no%10;
           rev=rev*10+r;
           no=no/10;

       }

       while(rev!=0)
       {

           r=rev%10;
           if(i%2==0)
           {
           even=even+r;
           }
           else
           {
           odd=odd+r;
           }
           rev=rev/10;
           i++;
       }

    printf("\n\t Odd  sum = %ld \n ",odd);
    printf("\n\t Even sum = %ld \n ",even);

    if(odd==even)
    printf("\n\t %ld Is Divisible by 11",n);
    else
    printf("\n\t %ld Is Not Divisible by 11",n);
    getch();

}

PROGRAM TO VERIFY PRIME NUMBERS PROPERTY


/***********************************************************************/
/* PROGRAM TO VERIFY PRIME NUMBERS PROPERTY                            */
/* AUTHOR : DEEPAK MAHAKALE 3 YEAR IT SRCOEM                           */
/* BLOG : www.mahakaledeepak.blogspot.com                              */
/***********************************************************************/

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

void main() {

  int n, prime, i, j, k, l;
  clrscr();
  printf("\n\t PROGRAM TO VERIFY PRIME NUMBERS PROPERTY");
  printf("\n\n\t Enter any number : ");
  scanf("%d", & n);

  printf("\n\t PRIME NO.  REMAINDER 1 WHEN DIVIDED BY 4 ");
  for (i = 2; i < n; i++) {
    prime = 1;
    for (j = 2; j < i; j++) {
      if (i % j == 0)
        prime = 0;
    }
    if (prime == 1) {
      // printf("\n\t %d",i);
      if (i % 4 == 1) {
        for (k = 1; k < n; k++) {
          for (l = 1; l < n; l++) {
            if ((k * k) + (l * l) == i) {
              printf("\n\t %d  -->  %d + %d = %d\ti.e %d SQ + %d SQ  ", i, k * k, l * l, i, k, l);
            }
          }
        }
      }
    }
  }
  printf("\n\n\n\t BY - DEEPAK MAHAKALE");
  getch();

}

PROGRAM TO VERIFY VALIDITY OF DATE


/***********************************************************************/
/* PROGRAM TO VERIFY VALIDITY OF DATE                                  */
/* AUTHOR : DEEPAK MAHAKALE 3 YEAR IT SRCOEM                           */
/* BLOG : www.mahakaledeepak.blogspot.com                              */
/***********************************************************************/

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

void main() {

  int d, m, y, y_i = 0, d_i = 0, leap = 0, i, d_l = 0;
  clrscr();
  printf("\n\t PROGRAM TO VERIFY VALIDITY OF DATE ");
  printf("\n\n\t Enter the date (dd mm yyyy) : ");
  scanf(" %d %d %d", & d, & m, & y);

  if (y < 1600 || y > 2100) // Change this range acc. to you...
  {
    printf("\n\t Year  invalid..");
    y_i = 1;
  } else {
    printf("\n\t Year  valid..");
  }

  if (y_i != 1) {
    if (y % 4 == 0)
      leap = 1;
  }

  if (m < 1 || m > 12) {
    printf("\n\t Month invalid..");
  } else {
    printf("\n\t Month valid..");
  }

  if (d < 1 || d > 31) {
    d_i = 1;
  }

  if (m >= 1 && m <= 7) {
    for (i = 1; i <= 6; i++) {
      if (m % 2 == 0)
        d_l = 30;
      if (m % 2 == 1)
        d_l = 31;
    }
  }

  if (leap == 0 && m == 2) {
    d_l = 28;
  }

  if (leap == 1 && m == 2) {
    d_l = 29;
  }

  if (m >= 8 && m <= 12) {
    for (i = 7; i <= 12; i++) {
      if (m % 2 == 0)
        d_l = 31;
      if (m % 2 == 1)
        d_l = 30;
    }
  }
  if (d > d_l)
    d_i = 1;

  if (d_i == 1)
    printf("\n\t Date  invalid..");
  if (d_i == 0)
    printf("\n\t Date  valid..");

  printf("\n\n\n\t BY - DEEPAK MAHAKALE");
  getch();

}

PROGRAM TO PRINT A CALENDAR


/********************************************************/
/* PROGRAM TO PRINT A CALENDAR                          */
/* AUTHOR : DEEPAK MAHAKALE 3 YEAR IT SRCOEM            */
/* BLOG : www.mahakaledeepak.blogspot.com               */
/********************************************************/

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

void main() {

  int i, j, f_d, t_d, dt = 1;
  clrscr();
  printf("\n\t PROGRAM TO PRINT A CALENDAR ");
  printf("\n\n\t Enter total no of days : ");
  scanf("%d", & t_d);
  printf("\n\t Enter first day <0-Mon..5-Sat,6-Sun> : ");
  scanf("%d", & f_d);

  printf("\n\n\t M \t T \t W \t T \t F \t S \t S \n");
  printf("\t _________________________________________________\n");

  for (j = f_d; j > 0; j--) {
    printf("\t");
  }

  while (dt <= t_d) {
    if (f_d != 0) {
      if (f_d % 7 == 0)
        printf("\n");
    }
    printf("\t %d", dt);
    dt++;
    f_d++;
  }

  printf("\n\n\n\t BY - DEEPAK MAHAKALE");
  getch();

}

Thursday, 30 August 2012

C PROGRAM TO DEMONSTRATE GRAPHICS GAME PRESS ME BUTTON

/* C PROGRAM TO DEMONSTRATE GRAPHICS GAME PRESS ME BUTTON  */ 
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR     */

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

union REGS i, o;
int left = 265, top = 250;

void initialize_graphics_mode() {
  int gd = DETECT, gm, error;

  initgraph( & gd, & gm, "C:/TC/BGI");

  error = graphresult();

  if (error != grOk) {
    perror("Error ");
    printf("Press any key to exit...\n");
    getch();
    exit(EXIT_FAILURE);
  }
}

void showmouseptr() {
  i.x.ax = 1;
  int86(0x33, & i, & o);
}

void hidemouseptr() {
  i.x.ax = 2;
  int86(0x33, & i, & o);
}

void getmousepos(int * x, int * y) {
  i.x.ax = 3;
  int86(0x33, & i, & o);

  * x = o.x.cx;
  * y = o.x.dx;
}

void draw_bar() {
  hidemouseptr();
  setfillstyle(SOLID_FILL, CYAN);
  bar(190, 180, 450, 350);
  showmouseptr();
}

void draw_button(int x, int y) {
  hidemouseptr();
  setfillstyle(SOLID_FILL, MAGENTA);
  bar(x, y, x + 100, y + 30);
  moveto(x + 5, y);
  setcolor(YELLOW);
  outtext("Press me");
  showmouseptr();
}

void draw() {
  settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
  outtextxy(155, 451, "www.programmingsimplified.com");
  setcolor(BLUE);
  rectangle(0, 0, 639, 450);
  setcolor(RED);
  outtextxy(160, 25, "Try to press the \"Press me\" button");
  outtextxy(210, 50, "Press escape key to exit");
  setfillstyle(XHATCH_FILL, GREEN);
  setcolor(BLUE);
  bar(1, 1, 75, 449);
  bar(565, 1, 638, 449);
  showmouseptr();
  draw_bar();
  draw_button(left, top);
}

void initialize() {
  initialize_graphics_mode();

  if (!initmouse()) {
    closegraph();
    printf("Unable to initialize the mouse");
    printf("Press any key to exit...\n");
    getch();
    exit(EXIT_SUCCESS);
  }

  draw();
}

int initmouse() {
  i.x.ax = 0;
  int86(0x33, & i, & o);
  return (o.x.ax);
}

void get_input() {
  int x, y;

  while (1) {
    getmousepos( & x, & y);

    /* mouse pointer in left of button */

    if (x >= (left - 3) && y >= (top - 3) && y <= (top + 30 + 3) && x < left) {
      draw_bar();
      left = left + 4;

      if (left > 350)
        left = 190;

      draw_button(left, top);
    }

    /* mouse pointer in right of button */
    else if (x <= (left + 100 + 3) && y >= (top - 3) && y <= (top + 30 + 3) && x > (left + 100)) {
      draw_bar();
      left = left - 4;

      if (left < 190)
        left = 350;

      draw_button(left, top);
    }

    /* mouse pointer above button */
    else if (x > (left - 3) && y >= (top - 3) && y < (top) && x <= (left + 100 + 3)) {
      draw_bar();
      top = top + 4;

      if (top > 320)
        top = 180;

      draw_button(left, top);
    }

    /* mouse pointer below button */
    else if (x > (left - 3) && y > (top + 30) && y <= (top + 30 + 3) && x <= (left + 100 + 3)) {
      draw_bar();
      top = top - 4;

      if (top < 180)
        top = 320;

      draw_button(left, top);
    }

    if (kbhit()) {
      if (getkey() == 1)
        exit(EXIT_SUCCESS);
    }
  }
}

int getkey() {
  i.h.ah = 0;
  int86(22, & i, & o);

  return (o.h.ah);
}

main() {
  initialize();

  get_input();
  return 0;
}

C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS


/* C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS             */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR  */

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

main() {
  int gd = DETECT, gm, midx, midy;

  initgraph( & gd, & gm, "C:/TC/BGI");

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

  setcolor(RED);
  settextstyle(SCRIPT_FONT, HORIZ_DIR, 3);
  settextjustify(CENTER_TEXT, CENTER_TEXT);
  outtextxy(midx, midy - 10, "Traffic Light Simulation");
  outtextxy(midx, midy + 10, "Press any key to start");
  getch();
  cleardevice();
  setcolor(WHITE);
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
  circle(midx, midy - 50, 22);
  setfillstyle(SOLID_FILL, RED);
  floodfill(midx, midy - 50, WHITE);
  setcolor(BLUE);
  outtextxy(midx, midy - 50, "STOP");
  delay(2000);
  graphdefaults();
  cleardevice();
  setcolor(WHITE);
  rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
  circle(midx, midy, 20);
  setfillstyle(SOLID_FILL, YELLOW);
  floodfill(midx, midy, WHITE);
  setcolor(BLUE);
  outtextxy(midx - 18, midy - 3, "READY");

  delay(2000);
  cleardevice();
  setcolor(WHITE);
  rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
  circle(midx, midy + 50, 22);
  setfillstyle(SOLID_FILL, GREEN);
  floodfill(midx, midy + 50, WHITE);
  setcolor(BLUE);
  outtextxy(midx - 7, midy + 48, "GO");
  setcolor(RED);
  settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
  outtextxy(midx - 150, midy + 100, "Press any key to exit...");

  getch();
  closegraph();
  return 0;
}