HOT C PROGRAMS BLOGSPOT

HOT C PROGRAMS BLOGSPOT

Click On Related Results For More Information

Sunday, 14 October 2012

Multiplication Table

 /*  Multiplication Multiply Table Tables  */

#include<stdio.h>
#include<conio.h>
void main()
{
 int num,i,a;
 clrscr();
 printf("Enter a number\t");
 scanf("%d",&num);
 for(i=1;i<=10;i++)
 {
  a=num*i;
  printf("    %d\n",a);
 }
 getch();
}




Saturday, 13 October 2012

Graphics Ellipse C Program

 /*  Works on XP */

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

int main(void)
{
int gd=DETECT,gm;
int cenx,ceny;
float Pk,a,b,x,y;
clrscr();

printf("\n\n Enter 'a' and 'b': ");
scanf("%f%f",&a,&b);

initgraph(&gd,&gm,"c:\\tc\\bgi");  /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
clrscr();
setcolor(5);

cenx=getmaxx()/2;
ceny=getmaxy()/2;

Pk=b*b-b*a*a+0.25*a*a;
x=0;
y=b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);

while (2*x*b*b <= 2*y*a*a)
{
if (Pk<0)
{
x=x+1;
y=y;
Pk=Pk+2*x*b*b+3*b*b;
}
else
{
x=x+1;
y=y-1;
Pk=Pk+2*x*b*b+3*b*b-2*y*a*a+2*a*a;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
delay(40);
}


Pk=(x+0.5)*(x+0.5)*b*b+(y-1)*(y-1)*a*a-a*a*b*b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
while (y>0)
{
if (Pk>0)
{
x=x;
y=y-1;
Pk=Pk-2*y*a*a+3*a*a;
}
else
{
x=x+1;
y=y-1;
Pk=Pk-2*y*a*a+3*a*a+2*x*b*b+2*b*b;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
delay(40);
}
gotoxy(1,25);
printf ("\npress any key to exit.");
getch();
closegraph();
return 0;
}




Networking Client Server C Program

/*  Networking Network Client Server C Program  */


/*  Posting more than one Program Of Each, Any one may run. Should Try all . Some Debugging may require. Program had run using RED HAT LINUX.  Dont know whether runs on any other OS or not*/

/*   Works on  RED HAT LINUX  */

Client Program No1.

#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>
#include<unistd.h>
#include<string.h>
#include<sys/time.h>

#define REMOTE_SERVER_PORT 1500

int main(int argc,char *argv[])
{ char msg[10];
 int sd,rc,i,client_len;
 struct sockaddr_in client_address,remote_server_address;
 if(argc<3) { printf("\n Number of arguments is less than <3 \n");exit(1);}
 remote_server_address.sin_family=AF_INET;
 remote_server_address.sin_addr.s_addr=inet_addr(argv[1]);
 remote_server_address.sin_port=htons(REMOTE_SERVER_PORT);
 sd=socket(AF_INET,SOCK_DGRAM,0);
 if(sd<0) { printf("\n Cannot open socket \n ");exit(1); }
 client_address.sin_family=AF_INET;
 client_address.sin_addr.s_addr=htonl(INADDR_ANY);
 client_address.sin_port=htons(0);
 rc=bind(sd,(struct sockaddr*)&client_address,sizeof(client_address));
if(rc<0) { printf("\n Cannot bind port \n"); exit(1);}

rc=sendto(sd,argv[2],strlen(argv[2]),0,(struct sockaddr*)&remote_server_address,         sizeof(remote_server_address));
if(rc<0) { printf("\n Cannot send data \n "); close(sd);exit(1);}

while(1)
{ memset(msg,0x0,10);
  client_len=sizeof(remote_server_address);
  rc=recvfrom(sd,msg,2,0,(struct sockaddr*)&remote_server_address,&client_len);
 
 if(rc<0) { printf("\n Cannto Receive data \n ");
 continue;
  }

printf("\n\n Result Received From Server % d \n ",msg[0]);
}
close(sd);
return 1;
}









Client Program No 2


#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>
#include<unistd.h>
#include<string.h>
#include<sys/time.h>

#define REMOTE_SERVER_PORT 1500

int main(int argc,char *argv[])
{ char msg[100];
 int sd,rc,i,client_len;
 struct sockaddr_in client_address,remote_server_address;
 if(argc<3) { printf("\n Number of arguments is less than <3 \n");exit(1);}
 remote_server_address.sin_family=AF_INET;
 remote_server_address.sin_addr.s_addr=inet_addr(argv[1]);
 remote_server_address.sin_port=htons(REMOTE_SERVER_PORT);
 sd=socket(AF_INET,SOCK_DGRAM,0);
 if(sd<0) { printf("\n Cannot open socket \n ");exit(1); }
 client_address.sin_family=AF_INET;
 client_address.sin_addr.s_addr=htonl(INADDR_ANY);
 client_address.sin_port=htons(0);
 rc=bind(sd,(struct sockaddr*)&client_address,sizeof(client_address));
if(rc<0) { printf("\n Cannot bind port \n"); exit(1);}

rc=sendto(sd,argv[2],strlen(argv[2]),0,(struct sockaddr*)&remote_server_address,         sizeof(remote_server_address));
if(rc<0) { printf("\n Cannot send data \n "); close(sd);exit(1);}

while(1)
{ memset(msg,0x0,100);
  client_len=sizeof(remote_server_address);
  rc=recvfrom(sd,msg,2,0,(struct sockaddr*)&remote_server_address,&client_len);
 
 if(rc<0) { printf("\n Cannto Receive data \n ");
 continue;
  }
//printf("\n Rc = %d",rc);
if(rc==2)
  { printf("\n\n Result Received From Server % d \n ",msg[0]); break;}
}
close(sd);
return 1;
}




























Server Program No. 1


#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>

#define LOCAL_SERVER_PORT 1500

int main(int argc, char *argv[])
 { char msg[10],x[2];
   int sd,rc,i,client_len,a,b,c;
   struct sockaddr_in client_address,server_address;
   sd=socket(AF_INET,SOCK_DGRAM,0);
   if(sd<0)
     { printf("\n Can not open Socket \n ");
       exit(1);
     }
   server_address.sin_family=AF_INET;
   server_address.sin_addr.s_addr=htonl(INADDR_ANY);
   server_address.sin_port=htons(LOCAL_SERVER_PORT);
   rc=bind(sd,(struct sockaddr *) &server_address,sizeof(server_address));
   if(rc<0)
          { printf("\n Can not bind port number \n ");
              exit(1);
            }
   while(1)
    { memset(msg,0x0,10);
      client_len=sizeof(client_address);
      rc=recvfrom(sd,msg,10,0,(struct sockaddr *)&client_address,&client_len);
      if(rc<0) { printf("\n Cannot receive data \n "); continue;}
      printf("\n Received from Client %d  %d  %d \n",msg[0],msg[1],msg[2]);
      a=msg[0];b=msg[2];
      a=a-48;b=b-48;c=a+b;x[0]=c;
      printf("\n In the Server the Result of Computation is %d \n\n",x[0]);
      break;
    }
  rc=sendto(sd,x,2,0,(struct sockaddr*)&client_address,sizeof(client_address));
  if(rc<0) { printf("\n Can not send data \n ");
                close(sd); exit(1);}
  return 1;
}



Server Program No. 2


#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>

#define LOCAL_SERVER_PORT 1500

int main(int argc, char *argv[])
 { char msg[10],x[2];
   int sd,rc,i,client_len,a,b,c;
   struct sockaddr_in client_address,server_address;
   sd=socket(AF_INET,SOCK_DGRAM,0);
   if(sd<0)
     { printf("\n Can not open Socket \n ");
       exit(1);
     }
   server_address.sin_family=AF_INET;
   server_address.sin_addr.s_addr=htonl(INADDR_ANY);
   server_address.sin_port=htons(LOCAL_SERVER_PORT);
   rc=bind(sd,(struct sockaddr *) &server_address,sizeof(server_address));
   if(rc<0)
          { printf("\n Can not bind port number \n ");
              exit(1);
            }
   while(1)
    { memset(msg,0x0,10);
      client_len=sizeof(client_address);
      rc=recvfrom(sd,msg,10,0,(struct sockaddr *)&client_address,&client_len);
      if(rc<0) { printf("\n Cannot receive data \n "); continue;}
      printf("\n Received from Client %d  %d  %d \n",msg[0],msg[1],msg[2]);
      a=msg[0];b=msg[2];
       a=a-48;b=b-48;c=a+b;x[0]=c;
       if(msg[1]=='+') c=a+b;
         else if(msg[1]=='-') c=a-b;
           else if(msg[1]=='*') c=a*b;
            else if(msg[1]=='/') c=a/b;
             else if(msg[1]=='%') c=a%b;
             x[0]=c;
      printf("\n In the Server the Result of Computation is %d \n\n",x[0]);
      break;
    }
  rc=sendto(sd,x,2,0,(struct sockaddr*)&client_address,sizeof(client_address));
  if(rc<0) { printf("\n Can not send data \n ");
                close(sd); exit(1);}
  return 1;
}

Graphics Line Rotation C Program

 /*   .......Works on Win XP      */
 /*   Graphics Line Rotation Rotate C Program  */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define pi 3.1456
void rotation(int,int,float);
int x1,y1,x2,y2,x3,y3,xf,yf,a;
float b;
void rotation(int xf,int yf,float b)
{
setcolor(GREEN);
line((x1*cos(b)-y1*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x1*sin(b)+y1*cos(b)-xf*sin(b)-yf*cos(b)+yf),(x2*cos(b)-y2*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x2*sin(b)+y2*cos(b)-xf*sin(b)-yf*cos(b)+yf));
line((x2*cos(b)-y2*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x2*sin(b)+y2*cos(b)-xf*sin(b)-yf*cos(b)+yf),(x3*cos(b)-y3*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x3*sin(b)+y3*cos(b)-xf*sin(b)-yf*cos(b)+yf));
line((x1*cos(b)-y1*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x1*sin(b)+y1*cos(b)-xf*sin(b)-yf*cos(b)+yf),(x3*cos(b)-y3*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x3*sin(b)+y3*cos(b)-xf*sin(b)-yf*cos(b)+yf));
}
void main(void)
{
int gd=DETECT,gm;
clrscr();
printf("enter 1st point=");
scanf("%d %d",&x1,&y1);
printf("\n enter 2nd point=");
scanf("%d %d",&x2,&y2);
printf("\n enter3rd point=");
scanf("%d %d",&x3,&y3);
printf("enter reference point=");
scanf("%d %d",&xf,&yf);
printf("enter the angle=");
scanf("%d",&a);
b=(pi*a)/180.0;
initgraph(&gd,&gm,"c:\\tc\\bgi");   /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
setcolor(WHITE);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3) ;
line(x1,y1,x3,y3);
rotation(xf,yf,b);
getch();
closegraph();
}





Graphics Reverse Diagonal Line C Program Figure

 /*   .......Works on Win XP      */


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(void)
{
   int gd=DETECT,gm,x=400,y=30;
   clrscr();
   initgraph(&gd,&gm,"c:\\tc\\bgi");   /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
   for(y=90;y<400;y++)
   {
      putpixel(x,y,RED);
      x--;
   }
   getch();
   closegraph();
   }





Thursday, 11 October 2012

Graphics Point Clipping C Program

/* .......Works on Win XP */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int tlx,tly,brx,bry,px,py;
void point_clip()
{ int wxmin,wymin,wxmax,wymax;
wxmin=tlx;
wxmax=brx;
wymin=tly;
wymax=bry;
if(px>=wxmin&&px<=wxmax)
if(py>=wymin&&py<=wymax)
putpixel(px,py,RED);
getch();
closegraph();
}
void main(void)
{ int gd=DETECT,gm,xc,yc,r;
clrscr();
printf("Enter the top left coordinate");
scanf("%d%d",&tlx,&tly);
printf("Enter the bottom right coordinate");
scanf("%d%d",&brx,&bry);
printf("\n Enter the point");
scanf("%d%d",&px,&py);
 initgraph(&gd,&gm,"c:\\tc\\bgi");  /*Sometimes it may be "C:\\TC\\BGI" , It depends machine to mac..*/
setbkcolor(YELLOW);
setcolor(RED);
rectangle(tlx,tly,brx,bry);
point_clip();
}






Graphics MidPoint Mid Point Circle C Program

/* .......Works on Win XP */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x1,y1;
void pt(int x,int y)
{putpixel(x+x1,y+y1,RED);
putpixel(-x+x1,y+y1,RED);
putpixel(-y+x1,x+y1,RED);
putpixel(-y+x1,-x+y1,RED);
putpixel(-x+x1,-y+y1,RED);
putpixel(x+x1,-y+y1,RED);
putpixel(y+x1,-x+y1,RED);
putpixel(y+x1,x+y1,RED);
}
void main()
{
int r,gd=DETECT,gm,x,y,d;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");   /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
printf("enter radius");
scanf("%d",&r);
printf("enter center of the circle-");
scanf("%d%d",&x1,&y1);
x=0;
y=r;
d=1-r;
while(x<=y)
{
pt(x,y);
if(d<0)
d=d+2*x+3;
else
{d=d+2*(x-y)+5;
y--;

}
x++;
}
getch();
closegraph();
}

Graphics Flood Fill C Program

 /* .......Works on Win XP */


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void flood_fill(int x,int y,int f,int o)
{ int current;
current=getpixel(x,y);
delay(2);
if(current==o)
{putpixel(x,y,f);
flood_fill(x,y+1,f,o);
flood_fill(x,y-1,f,o);
flood_fill(x+1,y,f,o);
flood_fill(x-1,y,f,o);;
}
}
void main()
{int gd=DETECT,gm,x,y,r,xc,yc,f,o;
clrscr();
printf("\nEnter the seed point");
scanf("%d%d",&x,&y);
printf("\nEnter the center & radius of the circle");
scanf("%d%d%d",&xc,&yc,&r);
printf("\nEnter the fill and old color");
scanf("%d%d",&f,&o);
initgraph(&gd,&gm,"C:\\TC\\BGI");   /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
setcolor(4);
circle(xc,yc,r);
flood_fill(x,y,f,o);
getch();
closegraph();
}


 /* Seed Pt and Center must be same,  Circle radius should be  less or equal to 30 otherwise machine may hang,  old colour be 0 always */










Graphics DAA Line Drawing C Program

/* .......Works on Win XP */

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

float abs(float);
float round(float);
int main() {
int gd=DETECT,gm,steps,k,dx,dy,x1,y1,x2,y2;
float xincr,yincr,x,y;
clrscr();
printf("Enter the co-ordinates of the starting point : ");
scanf("%d%d",&x1,&y1);
printf("Enter the co-ordinates of the end point : ");
scanf("%d%d",&x2,&y2);
dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
if(abs(dx) > abs(dy)) {
steps=abs(dx);
}
else {
steps=abs(dy);
}
xincr=(float)dx/steps;
yincr=(float)dy/steps;
 initgraph(&gd,&gm, "C:\\TC\\BGI");   /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
putpixel(round(x),round(y),RED);
for(k=0;k<steps;k++) {
x=x+xincr;
y=y+yincr;
putpixel(round(x),round(y),RED);
}
getch();
closegraph();
return 0;
}

float abs(float x) {
if(x>0) {
return x;
}
else {
return (-1*x);
}
}

float round(float x) {
int y;
y=(int)x;
if(x<(y+0.5)) {
return y;
}
else {
return (y+1);
}
}

Graphics Bresenham Line Drawing C Program

/* .......Works on Win XP */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,d,x1,x2,y1,y2,dx,dy,dt,ds;
clrscr();
 initgraph(&gd,&gm,"C:\\TC\\BGI");  /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
printf("Enter start and end coordinates x1 y1 & x2 y2 ");
scanf("%d%d%d%d",&x1,&y1,x2,y2);

dx=x2-x1;
dy=y2-y1;
dt=2*(dy-dx);
ds=2*dy;
d=2*dy-dx;
putpixel(x1,y1,YELLOW);
while(x1<x2)
{
x1++;
if(d<0)
d=d+ds;
else
{
y1++;
d=d+dt;
}
putpixel(x1,y1,YELLOW);
}
getch();
closegraph();
}

Graphics Bresenham Circle C Program

/*  Works on XP */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void pt(int,int);
int xc,yc,r;
void main()
{
int gm,gd=DETECT,x=0,y,d;
 clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");   /*Sometimes it may be "C:\\TC\\BGI" , It depends machine to mac..*/
printf("Enter the center x and y ");
scanf("%d%d",&xc,&yc);
printf("Enter the radius ");
scanf("%d",&r);
y=r;
d=3-2*r;
while(x<=y)
{
pt(x,y);
if(d<0)
d=d+4*x+6;
else
{d=d+4*(x-y)+10;
y--;
}
x++;
}
getch();
closegraph();
}
void pt(int x,int y)
{putpixel(x+xc,y+yc,4);
putpixel(y+xc,x+yc,4);
putpixel(-x+xc,y+yc,4);
putpixel(-y+xc,x+yc,4);
putpixel(-y+xc,-x+yc,4);
putpixel(-x+xc,-y+yc,4);
putpixel(x+xc,-y+yc,4);
putpixel(y+xc,-x+yc,4);
}

Graphics Boundary Fill C Program

/* .......Works on Win XP */
/*Works on XP but there is something wrong in it, needs some debug in program, Keep circle radius less than 30, Carefully give the old colour. */


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void boundary_fill(int x,int y,int f,int b)
{ int current;
current=getpixel(x,y);
delay(2);
if(current!=f && current!=b)
{putpixel(x,y,f);
  boundary_fill(x+1,y,f,b);
  boundary_fill(x,y+1,f,b);
  boundary_fill(x-1,y,f,b);
  boundary_fill(x,y-1,f,b);;
}
}
void main()
{int gd=DETECT,gm,x,y,r,xc,yc,f,b;
clrscr();
printf("\nEnter the seed point");
scanf("%d%d",&x,&y);
printf("\nEnter the center & radius of the circle");
scanf("%d%d%d",&xc,&yc,&r);
printf("\nEnter the fill and old color");
scanf("%d%d",&f,&b);
initgraph(&gd,&gm,"C:\\TC\\BGI");   /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
setcolor(4);
circle(xc,yc,r);
boundary_fill(x,y,f,b);
getch();
closegraph();
}

Wednesday, 10 October 2012

Addition

/* Addition Add Sum Using Third Variable*/

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
{
  printf ("\n enter the value of a & b");
scanf("%d %d",&a,&b);
c=a+b;
printf ("Add=%d",c);

}
  getch();
}

Tuesday, 9 October 2012

Graphics Triangle Figure C Program

 /*   .......Works on Win XP      */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(void)
{
   int gd=DETECT,gm,x,y;
   clrscr();
   initgraph(&gd,&gm,"c:\\tc\\bgi");  /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
   for(x=50;x<400;x++)
   {

   for(y=50;y<=x;y++)
   putpixel(x,y,RED);
   }
   getch();
   closegraph();
   }




Graphics Square Solid Figure C Program

 /*   .......Works on Win XP      */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(void)
{
   int gd=DETECT,gm,x,y;
   clrscr();
   initgraph(&gd,&gm,"c:\\tc\\bgi");    /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
   for(y=90;y<400;y++)
   for(x=90;x<400;x++)

      { putpixel(x,y,RED);

      }
   getch();
   closegraph();
   }



Monday, 8 October 2012

Graphics Kite C Program

#include <conio.h>
#include <stdio.h>
#include <graphics.h>
void main(void)
{
     int x,y,gm,gd=DETECT;
     clrscr();
     initgraph(&gd,&gm,"c:\\tc\\bgi");
     y=30;
     for(x=150;x<=250;x++)
     {
     putpixel(x,y,YELLOW);
     y++;
     }
     y=270;
     for(x=110;x<=250;x++)
     {
     putpixel(x,y,YELLOW);
     y--;
     }
     x=150;
     for(y=30;y<=130;y++)
     {
     putpixel(x,y,YELLOW);
     x--;
     }
     x=50;
     for(y=130;y<=270;y++)
     {
     putpixel(x,y,YELLOW);
     x++;
     }
     for(x=110;x<=190;x++)
     putpixel(x,y,YELLOW);
     for(y=30;y<=270;y++)
     {
     x=150;
     putpixel(x,y,YELLOW);
     }
     y=130;
     for(x=50;x<=250;x++)
     putpixel(x,y,YELLOW);
     getch();
     closegraph();
}





Calendar Year Date Day


#include<stdio.h>
#include<conio.h>
void cal(int yr,int mo,int fd,int da);
static char*months[]={
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"october",
"November",
"December"
};
void main()
{
clrscr();
static int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
long int ndays,ldays,tydays,tdays;
int d,i,m,fday,y;
char ch;
printf("Enter Year and Month    Eg. 2000 01\n");
scanf("%d %d",&y,&m);
ndays=(y-1)*365;
ldays=(y-1)/4-(y-1)/100+(y-1)/400;
tdays=ndays+ldays+1;
if((y%100==0&&y%400==0)||(y%4==0&&y%100!=0))
days[1]=29;
else
days[1]=28;
d=days[m-1];
tydays=0;
for(i=0;i<=m-2;i++)
tydays=tydays+days[i];
tdays=tydays+tdays;
fday=tdays%7;
cal(y,m,fday,d);
}
void cal(int yr,int mo,int fd,int da)
{int i,r,c;
char a;
clrscr();
gotoxy(25,2);
textcolor(RED);
cprintf("%s %d",months[mo-1],yr);
gotoxy(5,5);
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n   !   \n\n   !\n   !\n   !\n   !\n   !\n   !\n   !\n   !");
gotoxy(10,6);
textcolor(GREEN);
cprintf("Mon   Tue   Wed   Thu   Fri   Sat   Sun !");
gotoxy(5,7);
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\t\t\t\t\t\t !\n\n\t\t\t\t\t\t !\n\n\t\t\t\t\t\t !\n\n\t\t\t\t\t\t !\n\n\t\t\t\t\t\t");
r=9;
c=11+6*fd;
for(i=1;i<=da;i++)
{gotoxy(c,r);
textcolor(WHITE);
cprintf("%d",i);
if(c<=41)
c=c+6;
else
{c=11;
r=r+1;
}
}
gotoxy(5,15);
textcolor(YELLOW);
cprintf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
getch();
}

Sunday, 7 October 2012

Testing Palindrome



#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
void main()
{
    char str[20],str1[20]={0};
    int i,a,j=0;
    char c;
    clrscr();
    printf("\nEnter the string");
    scanf("%s",str);
    a=strlen(str)-1;
    i=a;
    while(i>=0)
     {
        while(j<strlen(str))
         {
            str1[j]=str[i];
            break;
         }
       i--;
       j++;
    }
  j=0;
  delay(600);
  printf("\n\nThe entered string is =  %s ",str);
  delay(600);
  printf("\n\nThe inverted string is = ");
  printf("%s",str1);
  a=strcmp(str,str1);
 if(a==0)
 {
   delay(600);
   printf("\n\nInput String = Inverted String. So");
   delay(600);
   printf("\n\nThe string is palindrome.");
 }
 else
 {
  delay(600);
     printf("\n\nThe string is not  palindrome");
    }
   getch();
 }

Graphics Diagonal Line

 /*   .......tested on Win XP      */


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(void)
{
   int gd=DETECT,gm,x=50,y=30;
   clrscr();
   initgraph(&gd,&gm,"c:\\tc\\bgi"); /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
   for(y=90;y<400;y++)
    {
      putpixel(x,y,RED);
      x++;
    }
   getch();
   closegraph();
  }

Friday, 5 October 2012

Graphics Vertical Line

/* Making Vertical Line Graphics  .......tested on Win XP      */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(void)
{
   int gd=DETECT,gm,x=50,y;
   clrscr();
   initgraph(&gd,&gm,"c:\\tc\\bgi");  /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
   for(y=90;y<400;y++)
   putpixel(x,y,RED);
   getch();
   closegraph();
  }