Translate

Labels

Tuesday 24 December 2013

GRAPH COLORING PROBLEM USING BACKTRACKING METHOD

#include<stdio.h>
#include<conio.h>
#define MAX 10
int G[MAX][MAX],edges;
int color_tab[MAX];
void main()
{
int i,j,n;
void Gen_col_value(int,int);
void Gr_coloring(int,int);
int get_data();
void display(int);
clrscr();
printf("\n\n\t Graph coloring \n");
for(i=0;i<MAX;i++)/*intialilisation of the graph and color table*/
{
for(j=0;j<MAX;j++)
{
G[i][j]=0;
color_tab[i]=0;
}
}
n=get_data();
Gr_coloring(1,n);
display(n);
getch();
}
void Gen_col_value(int k,int n)
{
int j,m;
int a,b;
while(1)
{
a=color_tab[k]+1;
b=m+1;
color_tab[k]=a%b;//next highest color
if(color_tab[k]==0)return;//all colors have been used
for(j=1;j<=n;j++)
{
//check if this color is distinct from adjacent colors
if(G[k][j]&&color_tab[k]==color_tab[j])
break;
}
if(j==n+1)return;//next new color found
}
}
//such that adjacent vertices are assigned distinct integers
//k is the index of next vertex color.
void Gr_coloring(int k,int n)
{
Gen_col_value(k,n);
if(color_tab[k]==0)return;//No new color available
if(k==n)return;//atmost m colors have been
else Gr_coloring(k+1,n);//used to color the n vertices
}
int get_data()
{
int m,v1,v2,i,n;
printf("\n Enter the number of nodes");
scanf("%d",&n);
printf("\n Enter the number of edges");
scanf("%d",&edges);
m=n-1;
printf("\n Enter the edges of the graph");
printf("By giving values of V1 and V2\n");
for(i=1;i<edges;i++)
{
scanf("%d%d",&v1,&v2);
G[v1][v2]=G[v2][v1]=1;//if na edge is present then set it
}
return n;
}
void display(int n)
{
int i;
printf("\n the vertices to be colored as....\n");
for(i=1;i<=n;i++)
printf("\nV%d:=%d",i,color_tab[i]);
}





                     Hello World Program without Semicolon>>>>>>>

Wednesday 18 December 2013

A C PROGRAM TO PRINT HELLO WORLD WITHOUT USING SEMICOLON

using if

main()
{
if(printf("Hello World")){
}}



using switch


main()
{
switch(printf("Hello World")){
}}



using while


main()
{
while(!printf("Hello World")){
}}


                                            TRY THIS

Monday 16 December 2013

STANDARD LIBRARY FUNCTIONS

Function                                Descriptions

abs()                                      Returns the absolute value of an integer.
absread()                               Read absolute disk sectors.
abswrite()                              Write absolute disk sectors.
arc()                                      Draws a circular arc.
asin()                                     Calculates the arc sine.
atof()                                     Converts a string to a floating point number.
bar3d()                                  Draws a 3-D bar.
biosdisk()                              ROM BIOS disk services.
bioskey()                               Keyboard interface,using BIOS services directly.
ceil()                                      Rounds up to a value representing the smallest integer that is greater than or equal to the argument.
chdir()                                   Changes current directory.
circle()                                   Draws a of the given radius at(x,y)
clearviewport()                      Clears the current viewport.
close()                                   Close a file.
closegraph()                           Shutdown the graphics system.
clrscr()                                   Clears the content of window in text mode.
coreleft()                                Returns the amount of RAM available for application programs.
cos()                                      Calculates the cosine of the angle specified in radians.
delay()                                   Suspends execution for an interval.
difftime()                                Computes the difference between the two times.
ellipse()                                  Draws an ellipse.
exit()                                      Terminates execution of the program.
fclose()                                   Closes file which has bees opened earlier.
fflush()                                    Flushes the specified stream.
fgetc()                                    Get a character from the specified stream.
fgets()                                     Gets a string from the specified stream.
findfirst()                                 Searches disk directory for the specified entry.
findnext()                                Continues findfirst() search.
floodfill()                                 flood-fills a bounded region.
fnsplit()                                   Split a file's path into four components-drive,directory,name,extension.
fopen()                                   Opens a file in specified mode.
fread()                                    Reads data from a stream.
free()                                      Frees allocated block of memory.
fscanf()                                   Scans and formats input from the specified stream.
fseek()                                    Repositions a file pointer on the specified stream.
fwrite()                                   Writes the data to the stream.
gcvt()                                      Converts floating point number to a string.
getc()                                      Gets character from a file.
getch()                                    Gets character from keyboard,does not echo it to screen.
getcwd()                                 Gets current working directory.
getdisk()                                 Gets current drive number.
getimage()                              Saves the bit image of the specified region of the screen into memory.
getlinesettings()                       Gets the current lines styles,pattern ,and thickness.
getmaxx()                               Returns  Maximum x-coordinates of screen.
getmaxy()                               Returns  Maximum y-coordinates of screen.
getpixel()                                Gets the color of a specified pixel.
gets()                                      Gets a string from keyboard.
getvect()                                 Gets the address of a ROM BIOS/DOS routine fro Interrupt Vector table.
gotoxy()                                  Positions cursor at specified position on screen.
graphresult()                            Returns an error code fro the last unsuccessful graphics operation.
imagesize()                              Returns the number of bytes required to store a bit image.
initgraph()                                Initialises the graphics system.
int86()                                     Issues software interrupt for calling ROM BIOS routine.
intdos()                                   Issues software interrupt for calling DOS routine.
isalnum()                                 Tests whether a character is an alphabet or a number.
isascii()                                   Tests whether a character is an ascii(0 to 127) character.
iscntrl()                                   Tests whether the character is the control character.
itoa()                                       Converts an integer to a string.
kbhit()                                     Checks for currently available keystroke.
line()                                        Draws a line between two specified points.
lineto()                                     Draws a line from the current position to (x,y)
ltoa()                                       Converts long to a string.
malloc()                                   Allocates a block of memory in RAM.
memmove()                             Copies a block of specified number of bytes.
memset()                                 Sets a given block of memory to specified byte.
moveto()                                 Moves the current position(CP) to (x,y).
nosound()                                Turns the speaker off.
open()                                     Opens a file for reading or writing.
outtext()                                   Display a string in the view port.
outtextxy()                               Display a string at a specified location on the screen.
peek()                                     Returns the word at memory location specified by segment;offset.
pieslice()                                  Draws and fills a pieslice.
pow()                                      Calculates x to the power of y.
printf()                                     Writes formatted output to the screen.
putc()                                       Output a character to a file.
putchar()                                  Output a  character on stdout.
putimage()                                Outputs a bit image on the screen.
putpixel()                                  Draws a pixel at a specified point on the screen.
puts()                                       Outputs a string on the screen.
random()                                  Generates a random number.
randomize()                              Initialises random number generator with a random value.
read()                                       Reads a chuck of bytes from a file.
registerfarbgidriver()                 Register linked in the graphics driver code with the graphics system.
registerfarbgifont()                    Registers linked in font code.
restorecrtmode()                      Restores the screen mode to its pre initgraph setting.
rewind()                                   Re position a file pointer to the beginning of a stream.
scanf()                                      Receives input from keyboard.
sector()                                     Draws and fills an elliptical pie slice.
setcolor()                                  Sets the current drawing color.
setfillstyle()                                Sets the fill pattern and color.
setlinestyle()                              Sets the current line width and style.
settextjustify()                            Sets text justification for graphics function.
settextstyle()                              Sets the current text characteristics for graphics output.
setvect()                                    Sets the address of a routine in Interrupt vector table.
setviewport()                             Sets the current view port for graphics output.
 sin()                                          Calculates the sine of the angle specified in radians.
sound()                                      Turns the speaker on at a specified frequency.
sprintf()                                      Writes formatted output to a string.
strcat()                                       Appends one string to another.
strcmp()                                     Compares one string with another.
strcpy()                                      Copies one string into another.
strlen()                                       Calculates the length of a string.
strncmp()                                   Compares a portion of one string to a portion of another.
strncpy()                                    Copies a given number of bytes from one string into another.
strnset()                                      Sets a specified number of characters in a string to a given character.
strstr()                                        Scan a string for the occurrence of a given sub-string.
strupr()                                      Converts lowercase letters in a string to uppercase.
system()                                     Issues a DOS command.
textmode()                                 Puts screen in textmode.
time()                                         Gets time of day.
write()                                        Writes a chuck of bytes to a file.




Saturday 7 December 2013

TRIANGLE OF STARS

A C program to print

*****
 ****
  ***
   **
    *

void main()
{
int i,j,k,n;
clrscr();
scanf("%d",&n);


for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
}
for(k=n-1;k>=i;k--)
{
printf("*"); 
}
printf("\n"); 
}
getch();

Friday 6 December 2013

TRIANGLE OF STARS

A C Program to Print          

    *
   **
  ***
 ****
*****
void main()
{
int i,j,k,n;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n-1;j>=i;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*"); 
}
printf("\n"); 
}
getch();