HOT C PROGRAMS BLOGSPOT

HOT C PROGRAMS BLOGSPOT

Click On Related Results For More Information

Thursday 11 October 2012

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();
  }