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

Tuesday 19 November 2013

A C PROGRAM TO FIND VOWELS COUNT

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

void main()
 {
   char letter;

   int vowel_count = 0;
   clrscr();
   
   for (letter = 'A'; letter <= 'Z'; letter++)
     switch (letter) {
       case 'A':
       case 'E':
       case 'I':
       case 'O':
       case 'U': vowel_count++;
     }; 

   printf("The number of vowels is %d\n", vowel_count);
   getch();
 }

Wednesday 13 November 2013

MESSAGE QUEUE FOR IMPLEMENTING THE MERGE SORT

A Program to utilize message queue for implementing the merge sort(Socket Programming)


#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/wait.h>
#include<stdlib.h>
#include<stdio.h>
#define MAXLINE 1000

struct mymesg
{
long mtype;
int a[4];
};
void Merge(int a[],int mer[],int ct)
{
if(ct==0)
{
ct+=4;
for(int i=1;i<=ct;i++)
mer[i]=a[i];
}
else
{
for(int i=1;i<=4;i++)
{
int j=1;
while(a[i]>mer[j]&&j<=ct)j++;
if(j>ct)
mer[j]=a[i];
else
{
for(int k=ct;k>=j;k--)
mer[k+1]=mer[k];
mer[j]=a[i];
}
ct++;
}
}
}
int main()
{
int n,pid,mpid,sum,b[17],mer[17],num=16;
mpid=msgget(12,0666|IPC_CREAT);
system("clear");
printf("Elements are...
");
for(int i=1;i<=num;i++)
{
b[i]=rand()%150;
printf("%d ",b[i]);
}
printf("

");
int i,ct=1,gmax;n=4;sum=0;gmax=4;
for(i=1;i<=n;i++)
{
struct mymesg ptr;
ptr.mtype=1;
pid=fork();
if (pid>0)
{
int k=0;
printf("Group %d: ",i);
for(int j=ct;j<=ct+gmax-1;j++)
{
ptr.a[++k]=b[j];
printf("%d ",ptr.a[k]);
}

printf("
");
msgsnd(mpid,&ptr,MAXLINE,IPC_NOWAIT);
waitpid(pid,NULL,0);

msgrcv(mpid,&ptr,MAXLINE,0,IPC_NOWAIT);

printf("Sorted Sub-Group %d: ",i);
for(int j=1;j<=gmax;j++)
printf("%d ",ptr.a[j]);
printf("

");

Merge(ptr.a,mer,ct-1);

if(ct==num+1-gmax)
break;
ct+=gmax;
continue;
}
else
{
msgrcv(mpid,&ptr,MAXLINE,0,IPC_NOWAIT);

for(int j=1;j<=gmax;j++)
{
for(int k=1;k<=gmax-j;k++)
{
if(ptr.a[k]>ptr.a[k+1])
{
int t=ptr.a[k+1];
ptr.a[k+1]=ptr.a[k];
ptr.a[k]=t;
}
}
}
ptr.mtype=2;
msgsnd(mpid,&ptr,MAXLINE,IPC_NOWAIT);
exit(0);
}
}
printf("Merged Sorted Group....
");
for(int i=1;i<=num;i++)
printf("%d ",mer[i]);
printf("

");
return 0;
}

Tuesday 12 November 2013

MOUSE POINTER USING C PROGRAM

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

void theend();

static int mask[]={/*SCREEN MASK*/
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                   0x0000,0x0000,
  /*CURSOR MASK*/
  0x0000,0x0000,0x381c,0x7c3e,0x7c3e,0x7c3e,0x7c3e,
  0x3bdc,0x07e0,0x0ff0,0x0ff0,0x0ff0,0x0ff0,0x07e0,
  0x03c0,0x0000};


void main()
{int gdriver=DETECT,gmode,buttons;
 union REGS regs;
 struct SREGS sregs;
 initgraph(&gdriver,&gmode,"");
 regs.x.ax=0;                        /*INITIALIZE MOUSE*/
 int86(0x33,®s,®s);
 setcolor(LIGHTCYAN);
 if(regs.x.ax==0)
   {outtextxy(0,0,"NO MOUSE AVAILABLE");
    getch();
    theend();
   }
 regs.x.ax=9;                       /*CHANGE CURSOR SHAPE*/
 regs.x.bx=5;
 regs.x.cx=0;
 regs.x.dx=(int)mask;
 segread(&sregs);
 sregs.es=sregs.ds;
 int86x(0x33,®s,®s,&sregs);
 regs.x.ax=1;                       /*SHOW MOUSE POINTER*/
 int86(0x33,®s,®s);
 do
   {regs.x.ax=3;
    int86(0x33,®s,®s);
    buttons=regs.x.bx & 3;
   }while(buttons!=3);
 regs.x.ax=2;                       /*HIDE MOUSE POINTER*/
 int86(0x33,®s,®s);
 theend();
}

void theend()
{
closegraph();
}

Sunday 27 October 2013

RIGHT ANGLED TRIANGLE OF STARS

Program to print 

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

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

C PUZZLES

Assignment Operators

What dopes the following program print?
#define PRINTX printf("%d\n",x)

main()
{
int x=2,y,z;
x*=3+2;
PRINTX;
x*=y=z=4;
PRINTX;
x=y==z;
PRINTX;
x==(y=z);
PRINTX;
}


Explanation


Tuesday 8 October 2013

RIGHT ANGLED TRIANGLE OF STARS

Program to print Right Angled Triangle of Stars

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

for(i=0;i<=n;i++)
{

Tuesday 13 August 2013

C PUZZLES

Basic Arithmetic Operators

mian()
{
int x;
x=- 3 + 4 * 5 -6;    /*1*/
printf("%d\n",x);
x=3 + 4 % 5 - 6;     /*2*/
printf("%d\n",x);
x=- 3 *4 %-6 / 5;    /*3*/
printf("%d\n",x);
x=(7+6)%5/2;         /*4*/
printf("%d\n",x);
}


1.x=- 3 + 4 * 5 -6;             by reading the precedence table

   x=(- 3) + 4 * 5 -6;          The highest level operator in the expression is the unary -. We'll use                                                                parentheses indicate the order of binding operands to operators. 
   x=(- 3) + (4 * 5) -6;        Next highest in the expression is *.

  

Friday 2 August 2013

PROGRAM TO FIND GCD OF TWO INTEGERS

GCD
mian()
{
int a,b ;
printf("Enter two positive integers :\n");
scanf("%d%d",&a,&b);
printf("GCD of %d and %d is %d\n",a,b,gcd(a,b));
}
gcd(int a,int b)
{
if(a)
return(b?gcd(b,a%b):a);
else
return b;
}



OUTPUT
Enter two positive integers
24   36
GCD of 24 and 36 is 12

Saturday 13 July 2013

PASSING 2-D ARRAY TO A FUNCTION

There are three ways in which we can pass a 2-D array to a function.these are illustrated in the following program.

main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9,8,7,6};
clrscr();
display(a,3,4);
show(a,3,4);
print(a,3,4);
}


Tuesday 2 July 2013

GET IP ADDRESS USING C PROGRAM

#include<stdlib.h>
int main()
{
system("C:\\windows\\system32\\ipconfig");
return 0;
}

Friday 21 June 2013

FIBONACCI SERIES USING ARRAYS

#include<stdio.h>
#include<conio.h>
main()
{
int a[30];
int x,n;
clrscr();
printf("Enter no.of times to print:");
scanf("%d",&n);
printf("\n FIBONACCI SERIES :");

Thursday 20 June 2013

PROGRAM TO HIDE THE SYNTAX OF C

#define BEGIN main(){
#define END}
#define EQUAL ==
#define READ(N) scanf("%d",&N)
#define WRITELN(N) printf("%d\n",N)

Sunday 16 June 2013

POINTER ARITHMETIC

Address + Number= Address Address - Number= Address Address - Address=Number Address + Address=Illegal

PROGRAM FOR SHUTDOWN TIMER

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
void main()
{
int t,i,s;
clrscr();
printf("enter the time in sec:");
scanf("%d",&t);

PROGRAM TO INSERT AN ELEMENT IN AN ARRAY

#define MAX 10
main()
{
int a[MAX]={11,22,33,44,55,77,88};
int n,x;
printf("Enter an element to be inserted \n");
scanf("%d",&x);
printf("Enter the position at which\n");
printf("this element to be inserted \n");
scanf("%d",&n);
insert(a,x,n);
}

PROGRAM TO STORE A FLOAT VALUE IN THE MEMORY

#include<malloc.h>
main()
{
float *fp;
fp=(float*)malloc(sizeof(float));
/*Initialization of pointer variable*/

PROGRAM TO FIND INTEGRAL VALUE USING SIMPSON'S RULE

#define f(x) 1.0/(1+x*x)
main()
{
int n;
float simps(float,float,int)a,b;
printf("Enter the values of a,b and n\n");
scanf("%f%f%d",&a,&b,&n);
printf("Integral value of f(x) by simpson's 1/3 rule:%f\n",simps(a,b,n));
}

Saturday 15 June 2013

PROGRAM TO FIND THE INTEGRAL VALUE USING TRAPEZOIDAL RULE

#define f(x) 1.0/(1+x*x)
main()
{
int n;
float a,b;
float trapz(float,float,int);
printf("Enter the values of a,b and n\n");
scanf("%f%f%d",&a,&b,&n);
printf("Integral value of f(x) by trapezoidal rule:%f\n",trapz(a,b,n));
}

Friday 14 June 2013

PROGRAM TO FIND EXECUTION TIME OF A PROGRAM

#include<time.h>
main()
{
time_t t1,t2;
clock_t clock(void);
int i,x=0,y=10;
t1=clock();

PROGRAM TO CONVERT 2-D ARRAY TO 1-D ARRAY

#define MAXROW 3
#define MAXCOL 2
main()
{
int a[MAXROW][MAXCOL],B[MAXROW*MAXCOL];
INT I,J,K=0;
printf("Enter the matrix elements in row order\n ");
for(i=0;i<MAXROW;i++);
for(j=0;j<MAXCOL;j++);
{
scanf("%d",&a[i][j]);
b[k++]=a[i][j];
}

Thursday 13 June 2013

PROGRAM TO SOLVE TOWER OF HANOI PROBLEM

main()
{
int source,destination,other,nodisks;
printf("Enter the number of disks:\n");
scanf("%d",&nodisks);
if(nodisks<1)
{
printf("Illegal input\n");
exit(1);
}
source=1;
other=2;
destination=3;

Wednesday 12 June 2013

PROGRAM TO GENERATE PREFECT NUMBERS

main()
{
int n,i,sum=0,count=0;
for(n=4; ;n++)
{
sum=0;
for(i=1;i<n/2;i++)
{
if((n%i)==0)
sum+=i;
}

AUTO VARIABLES HAVING SAME NAME IN DIFFERENT BLOCKS

main()
{
auto float f1=20.4;
{
auto float f1=10.8;
{
auto float f1=5.3;
printf("Inner block : f1=%.2f , f1+10=%.2f\n",f1,f1+10);
}
printf("Middle block : f1=%.2f , f1+10=%.2f\n",f1,f1+10);
}
printf("Outer block : f1=%.2f , f1+10=%.2f\n",f1,f1+10);
}

Tuesday 11 June 2013

PROGRAM TO GENERATE QUEER NUMBERS

main()
{
int i;
printf("The generated queer numbers:\n");
for(i=11;i<2000;i++)
if(queer(i)!=0)
printf("%d",queer(i));
printf("\n");
}

Monday 10 June 2013

CONVERSION OF INTEGERS INTO WORDS

#include<stdio.h>
#include<conio.h>
main()
{
char a[10][10]={"one","two","three","four","five","six","seven","eight","nine","ten"};
char b[10][10]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
char c[10][10]={"ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety","hundred"};
int s,r,t;
long n;
clrscr();
/*Enter the number below one lakh*/
printf("Enter the number:");
scanf("%ld",&n);

Saturday 8 June 2013

PASCAL'S TRIANGLE

#include<stdio.h>
#include<conio.h>
main()
{
int b,p,q,r,x;
clrscr();
printf("Enter no.of rows:");
scanf("%d",&r);
b=1;
q=0;
printf("\n PASCAL'S TRIANGLE \n");

ACHROMATIC STRING

#include<stdio.h>
#include<conio.h>
main()
{
char ch[100];
int i;
clrscr();
printf("Enter any string:");
/*to accept multi word string gets() is used*/

Friday 7 June 2013

PROGRAM TO IMPLEMENT RE-CALIBRATE COMMAND

#include #include #include void main(){int show; clrscr();//Put on the motor outp(0x3f2,28); // Check whether the FDC is ready show=inp(0x3f4);//Read the status of MAIN STATUS REGISTER show=(show&amp;128); if(show==128)//Check whether FDC is ready

PROGRAM FOR ENABLING AND DISABLING THE KEYBOARD

#include #include #include main() 

 clrscr();
 outportb(0x64,0xAD); /*Code for disabling the KEYBOARD*/
 printf(" Keyboard Disabled");
 delay(10000);

PROGRAM FOR VERIFYING THE DISK SECTOR

#include #include #include void main(void) 

 clrscr();
 union REGS regs;
 struct SREGS sregs; 
 char buff[1000];
 int i; 
 regs.h.ah = 4; 
 regs.h.al = 1;
 regs.h.ch = 1; 
 regs.h.dh = 0; 
 regs.h.cl = 1; 
 regs.h.dl = 0x80; 

PROGRAM FOR READING THE DISK'S DATA ONTO THE BUFFER

#include #include #include void main(void)
 { 
 clrscr();
 union REGS regs;
 struct SREGS sregs;
 char buff[1000]; 
 int i;
 regs.h.ah = 2;
 regs.h.al = 1;
 regs.h.ch = 1; 
 regs.h.dh = 0; 
 regs.h.cl = 1; 
 regs.h.dl = 0x80; 

PROGRAM FOR GETTING THE DISK STATUS

#include #include #include void main(void) 

 clrscr();
 union REGS regs;
 regs.h.ah = 1; 
 regs.h.dl = 0x80;

PROGRAM FOR RESETTING THE FDC IC (FLOPPY DISK CONTROLLER)

#include #include #include void main(void) 
 {
 clrscr();
 union REGS regs;
 regs.h.ah = 0; 

PROGRAM FOR SETTING THE CURSOR SIZE

#include #include #include void main(void)
 {
 clrscr();
 int x,y;
 union REGS regs;
 printf(&quot; Enter the starting line of the cursor(0-4) - &quot;); 
 scanf(&quot;%d&quot;,&amp;x);
 printf(&quot; Enter the ending line of the cursor - &quot;); 
 scanf(&quot;%d&quot;,&amp;y);

PROGRAM FOR SCROLLING THE WINDOW DOWN

#include #include #include void main(void) 
{
 clrscr(); 
union REGS regs;
 regs.h.ah = 07;
 regs.h.al = 5;
 regs.h.bh = 8; 
 regs.h.ch = 0;

PROGRAM FOR SETTING THE CURSOR POSITION AT DESIRED LOCATION

#include #include #include void main(void) 
{
 clrscr();
 int x,y;
 union REGS regs;
 printf(&quot; Enter the X-position - &quot;); 
scanf(&quot;%d&quot;,&amp;x);
 printf(&quot; Enter the Y-position - &quot;);
 scanf(&quot;%d&quot;,&amp;y);

Wednesday 5 June 2013

PROGRAM FOR SCROLLING THE WINDOW UP


#include #include #include void main(void)
 {
 clrscr();
 union REGS regs;
 regs.h.ah = 06;
 regs.h.al = 5;
 regs.h.bh = 8; 
regs.h.ch = 0;

Friday 24 May 2013

KNAPSACK PROBLEM

C PROGRAM TO IMPLEMENT KNAPSACK PROBLEM  USING BACKTRACKING

#include<stdio.h>
#include<conio.h>
float final_profit=-1.0;
intp[9]={0,11,21,31,33,43,53,55,65};
int w[9]={0,1,11,21,23,33,43,45,55};
int m=110;
int n=8;
int temp[9],x[9];
float final_wt=-1.0;
float bound_calculation(int cp,int cw,int k)
{
int ub,c,i;
ub=cp;
c=cw;
for(i=k+1;i<n;i++)
{
c=c+w[i];
if(c<m)
ub=ub+p[i];
else
return(ub+(1-(c-m)/w[i]*p[i]));
}
return ub;
}
void BK(int k,int cp,int cw)
{
int new_k,new_cp,new-cw,j;
//Generate left child
if(cw+w[k]<=m)
{
temp[k]=1;
if(k<n)
{
new_k=k+1;
new_cp=cp+p[k];
new_cw=cw+w[k];
BK(new_k,new_cp,new_cw);
}
if((new_cp>final_profit)&&(k==n))
{
final_profit=new_cp;
final_wt=new_cw;
for(j=1;j<k;j++)
x[j]=temp[j];
}
}

//Generate right child
if(Bound_calculation(cp,cw,k)>==final_profit)
{
temp[k]=0;
if(k<n)
BK(k+1,cp,cw);
if((cp>final_profit)&&(k==n))
{
final_profit=cp;
final_wt=cw;
for(j=1;j<n;j++)
x[j]=temp[j];
}
}
}
void main()
{
int i;
clrscr();
printf("\n\t Knapsack problem using backtracking algorithm \n");
printf("\n Capacity of knapsack=%d",m);
printf("\n\n Profit\t Weight");
printf("\n-------------------------------");
for(i=1;i<=n;i++)
printf("\n%d\t%d",p[i],w[i]);
printf("\n-------------------------------");
BK(1,0,0);
printf("\n Following items are selected from knapsack...");
for(i=1;1<=n;i++)
{
if(x[i]==1)
printf("\n\t\t Item %d",i);
}
printf("\n\n Final Weight =%0.2f",final_wt);
printf("\n Final Profit=%0.2f",final_profit);
getch();
}

OUTPUT:
Knapsack problem using Backtracking algorithm

capacity of knapsack=110

Profit weight
-----------------------------
11     1
21     11
31     21
33     23
43     33
53     43
55     45
65     55
-----------------------------
Following item are selected from knapsack...
Item 1
Item 2
Item 3
item 5
Item 6
Final weight=109.00
final Profit=159.00

Thursday 16 May 2013

DIFFERENCE BETWEEN TSR AND TSO PROGRAM

TSO means terminate but stay outside.It is those programs which release the memory after the execution of the program.Eg VCD cutter,turbo c compiler.TSR means terminate but stay residence.It is those programs which after the execution of the program does not release the RAM(main memory).Eg antivirus 

n-QUEEN'S PROBLEM USING BACKTRACKING

/*This program is to implement n-queen's problem using backtracking*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>

int board[20];
int count;
void main()
{
int n,i,j;
void queen(int row, int n);
clrscr();
printf("\n\t Program for queen's using backtracking");
printf("Enter number of queen's ");
scanf("%d",&n);
queen(1,n);                                      //trace using backtrack
getch();
 }


/*This function is for printing the solution to n-queen's problem*/
void print_board(int n)
{
int i,j;
printf("\n\n solution %d:\n\n",++count);
//number of solution
for(i=1;i<=n;i++)
{
printf("\t%d",i);
}
for(i=1;i<=n;i++)
{
printf("\n\n%d",i);
for(j=1;j<=n;j++)        //for n*n board
{
if(board[i]==j)
printf("\tQ");   //Queen at i,j position
else
printf("\t-");   //empty slot
}
}
printf("\n Press any key to continue.....");
getch();
}
/*This function is for checking for the conflicts.If there is no conflict for the desired position it returns 1 otherwise it returns 0*/
int place(int row ,int column)
{
int i;
for(i=1;i<=row-1;i++)
{
//checking for column and diagonal conflicts 
if(board[i]==column)
return 0;
else
if(abs(board[i]-column)==abs(i-row))
return 0;
}
//no conflicts hence Queen can be placed
return 1;
}



Tuesday 7 May 2013

QWERTY QUERY

The layout of the keyboard comes in various styles, such as QWERTY, AZERTY, and DVORAK. QWERTY is the most common layout in English language computer keyboards.It takes its name from first six letters shown on the keyboard's top row of the letters.Similarly,French language keyboard use A and Z in place of Q and W and are known as AZERTY keyboards 

WHAT'S IN THE NAME? CD BURNING

CD-Rs and CD-RWs are made up of a poly carbonate substrate, a thin metal coating, and a protective outer layer.In a CD-R a layer of organic polymer dye between the poly carbonate and the metal layers serves a a recording medium. The laser creates marks(burns) in the dye layer that mimic the reflective properties of the pits and lands(lower and higher areas) of the cd.Due to this CD writing is also known as CD BURNING 

Monday 29 April 2013

SHOWING DATE AND TIME OF YOUR LOCAL PC TIME USING C PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
textcolor(6);
cprintf("Showing date and time \n");
printf("\n");
textcolor(2);
cprintf("Date:%s",DATE);
printf("\n");
textcolor(4);
cprintf("Time:%s",TIME);
getch();
}

cprintf() function you can see color formatted output.
textcolor() function gives the specific color.
By executing this program you can see the current date and time of your local PC time.

Saturday 27 April 2013

ALL PERFECT SQUARE BELOW 1000

/*PROGRAM TO PRINT ALL PERFECT SQUARES BELOW 1000*/
#include<stdio.h>
main()
{
int i=1;
printf("The perfect squares below 1000 are\n");
while(i*i<1000)
{
printf("%5d",i*i);
i++;
}
getch();
}

SUM THE FIRST 50 EVEN NATURAL NUMBERS

/*PROGRAM TO SUM THE FIRST 50 EVEN NATURAL NUMBERS*/
#include<stdio.h>
main()
{
int sum=0,i=2;
while(i<=100)
{
sum+i;
i+=2;
}
printf("Sum of first 50 even natural numbers=%d\n",sum);
getch();
}

OUTPUT
Sum of first 50 natural numbers=2550


Sunday 14 April 2013

DENSITY OF TAPE

Density of a tape is referred to as the number of frames per inch(fpi) or character per inch(cpi) rather than bits/bytes per inch(bpi) Regardless of which term is used,a frame or byte is a group of related bits that make up a single character written across the width of the tape.

IBM

In 1896,Hollerith founded the Tabulating Machine company,which was later named IBM (International Business Machines)IBM developed numerous mainframes and operating systems,many of which are still in use today.For example IBM co-developed  OS/2 with Microsoft, which laid the foundation for windows operating system.

Saturday 6 April 2013

USB SYSTEM LOCK

BOOT LOCK

This lock will allow you to use your USB stick as a key to boot into windows.If someone tries to start the computer without your USB stick, it will display boot errors. Before we begin let us tell you that playing with the BIOS and files of your computer may result in you not being able to boot into your partition;so continue at your own risk!
Now that we have absolved ourselves of all guilty,let's begin.
Things you need:A 64MB or larger sized USB stick,windows recovery disk.(Just in case)
Steps:
1) Unhide hidden and protected files: goto Tools>options>view, check show hidden files and unchecked hide protected system files.

2)From the driver where Windows is installed(normally C:\), copy the files boot.ini,ntdlr and NTDETECT.COM to your USB Stick.

3)Now,we need to go into your BIOS,so restart the computer and keep jabbing[F8] as soon as the computer starts.

4)Once in the BIOS,enable USB Drive as the first boot device.You might have to enable USB Legacy support on older BIOSes.

5)Restart your computer if all goes well you should be able to lg into windows.If not,then unplug the USB stick,return to the BIOS and change the first Boot device to your hard disk and repeat the steps above.

6)Once your are logged into Windows drive and rename boot.ini to boot.bak.

7)To check if you have setup everything correctly,eject your USB stick and reboot the computer.You should get error messages on the screen such as "Invalid Boot.ini" or "Windows could not start".

8)In case Windows does not load,use yours windows recovery disk by following the steps mentioned at http://tinyurl.com/s9sd2.

The other way

For the less brave-hearted,  instead of preventing Windows from booting you can choose to just lock your computer with your USB stick.

USB system Lock

A freeware program,USB system lock Works flawlessly while locking and unlocking your computer.When you install USB System Lock, it detects your USB stick  and creates a digital key on it.This key is used by the program to authenticate the user and log into the computer.
Strangely,the program is not included in the start-up list by default.
to add it there,you need it to drag agent from the USB system lock entry under all programs to the start up folder in the same menu.If you happen to accidentally delete the key from your USB stick while working on the protected computer you can reassign a key using start>programs>USB system lock>Key Disk Generator.

My Lock 2.0

This program takes USB-based computer locking to whole new level.You can look access to not only your PC but the keyboard,CD Drive and even access to safe mode.You can also set a particular time for the computer to automatically lock itself.What is most interesting about the phrase so that you can use it log into the computer even without the stick plugged in

Friday 5 April 2013

PROCESSING ONE DIMENSIONAL ARRAY

TO SEARCH FOR A NUMBER IN A LIST OF NUMBERS

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10},n,i,f,s;
clrscr();
printf("Enter the no of numbers \n");
scanf("%d",&n);
printf("Enter %d numbers \n",n);
for(i=0;i<n;i++)
scanf("%d",a[i]);
printf("Enter the number to be searched \n");
scanf("%d",&s);
/* searching for s in a begins */ 
f=0;
for(i=0;i<n;i++)
if(a[i]==s)
{
f=1;
break;
}
/*searching for s in a ends*/
printf("\n List of elements \n");
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("\n Enter to be searched \n");
printf("\n s=%d \n",s);
if(f==1)
printf("%d is found",s);
else
printf("%d is not found",s);
getch();
}
OUTPUT
Enter the no of numbers
5
Enter 5 numbers
1   2   3   4   5
Enter the number to be searched 
3
List of elements 
1   2   3   4   5
Elements to be searched
3
3 is found
Explanation
a is declared to be array of int type of size 10.Maximum 10 values can be read into the array.n,i,s and f are declared to be variable of int type.n is to collect the number of values to  be read into a, which lies within 1 and 10.i is to traverse all the elements of a.s is to collect a value which is to be searched.f is to be determine whether s is found in a or not.It acts as a flag variable.The procedure of searching for s in a is implemented in the following segment of the program.
f=0;
for(i=0;i<n;i++)
if(a[i]==s)
{
f=1;
break;
}
before searching begins,f is set to zero with the assumption that s is not available in a.During the course of searching that is inside the body of the for loop, if s is found t match with any element in the array, f is set to 1  and loop is excited. If s takes 1 then it means s  is found in a.If f retains 0,we conclude that s s not fond in a.The value of f would thus tell us whether s is found in a or not.  

Thursday 4 April 2013

PROCESSING ONE DIMENSIONAL ARRAY

TO ACCEPT A LIST OF NUMBERS INTO A 1-d ARRAY, FIND THEIR SUM, AVERAGE AND DISPLAY THEM.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n, sum;
float avg;
clrscr();
printf("Enter no.of elements [1-10]\n");
scanf("%d",&n);
printf("Enter %d numbers \n ",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("The number are \n");
for(i=0;i<n;i++)
printf("%4d",a[i]);
/*Finding the sum and average begins*/
sum=0;
for(i=0;i<n;i++)
sum+=a[i];
avg=(float)sum/n;
/*Finding the sum and average ends*/
printf("\n Sum=%d\n",sum);
printf("\n Average=%f\n",avg);
getch();
}
OUTPUT
Enter no.of elements[1-10]
5
Enter 5 numbers
1   2   3   4   5
The numbers are
1   2   3   4   5
Sum=15
Average=3.000000
Explanation
a is declared to be an array of int type and of size 10.Maximum 10 numbers can be written into the array.n,i and sum are declared to be variable of int type.n is to collect the number of values to be read into the array a,which lies within 1 and 10.i is to traverse all values in a sum is to collect the sum of the values in a avg is declared to be a variable of float type and it is to collect the average of values in a.
In the process of finding the sum of all the values initially sum is set to 0.A for loop is used select each number in the array and it added to sum with the statement.
sum+=a[i]
The statement
avg=(float)sum/n;
on its execution assign average value to avg. Note that we have used type casting to convert sum forcibly to float to get the exact result.Otherwise the expression (sum/n) produces only integral part of the quotient since both sum and n are integers.Both sum and avg are then displayed 

Wednesday 3 April 2013

PROCESSING ONE DIMENSIONAL ARRAYS

TO ILLUSTRATE DECLARATION, INITIALIZATION OF A ONE-DIMENSIONAL ARRAY AND DISPLAYS ITS ELEMENTS.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[5]={2,3,5,6,7};
clrscr();
printf("The elements of array a \n");
for(i=0;i<=4;i++)
printf("%3d",a[i]);
getch();
}
OUTPUT:
The element of array a
2   3   5   6   7
Explanation
a is declared to be an array of int type and of size five and also is initialized while it is declared.i is a variable of int type and it is used to traverse the elements of a.
To display the elements of a,we have used for loop to repeatedly call printf().The loop variable i is made to range from 0 to 4.When i takes 0, the first element is displayed.When i takes 1,the second element is displayed and so on.  

Tuesday 2 April 2013

X TO THE POWER Y

#include<stdio.h>
#include<conio.h>
float power(int x,int y)
{
float p;
if(y==0)
return(1);
else if(y>0)
p=x*power(x,y-1);
else
{
p=1/power(x,-y);
}
return(p);
}
void main()
{
int x,y;
float p;
clrscr();
printf("Enter values of X and y \n");
scanf("%d%d",&x,&y);
p=power(x,y);
printf("%f",p);
getch();
}

OUTPUT
Enter values of X and Y
2
3
8.000000
Enter values of X and Y
2
-2
0.25
Enter values of X and Y
3
0
1

BOMB GAME

/*
REQUEST for all game players :
KEEP NUM LOCK , CAPS , SCROLL LOCK OFF
Lft Shift ==> Move left
Rht Shift ==> Move right
Any Ctrl ==> Fire on Bomb on path.
*/

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
unsigned char far *vidmem=0xB8000000;
void write(unsigned char,unsigned char,unsigned char);
unsigned char read(unsigned char,unsigned char);
void main()
{
unsigned char far *keybmem=0x417;
unsigned char counter=0,destroyed=0,speed=0,bombposx=0,bombposy=0,temp=0,sleeper=250,row,col,curcol=40;
unsigned char bombactive='n';
/*make it boolean later*/
int i,j=0;
clrscr();
printf("REQUEST for all game players :\n\nKEEP NUM LOCK , CAPS , SCROLL LOCK OFF\nLft Shift ==> Move left\nRht Shift ==> Move right\nAny Ctrl ==> Fire on Bomb on path.\n\n\tPress any key to Continue...");
getch();
clrscr();
for(i=0;i<25;i++)
{
write(0,i,32);
write(79,i,32);
}
write(curcol,0,30);
write(0,23,1);
write(79,23,1);
*keybmem=0;
for(;;)
{
if(bombactive=='n'&&counter<26)
{
counter=0;
temp=counter;
for(;;)
{
bombposx=random(80);
if(bombposx>curcol&&bombposx-curcol<20)
break;
else
if(curcol>bombposx&&curcol-bombposx<20)
break;
}
if(bombposx!=0&&bombposx!=79)
{
write(bombposx-1,0,'_');
write(bombposx+1,0,'_');
}
bombposy=24;
write(bombposx,bombposy,31);
bombactive='y';
counter++;
}
if(bombactive=='y'&&counter>25)
{
bombactive='n';
write(bombposx,bombposy,32);
if(bombposx!=0&&bombposx!=79)
{
write(bombposx-1,0,32);
write(bombposx+1,0,32);
}
sound(100);/*UNDESTROYED BOMB HITTING GROUND*/
delay(50);
nosound();
counter=0;
}
if(bombactive=='y'&&counter<26)
{
if((counter-temp)==1)
{
temp=counter;
write(bombposx,bombposy,32);
write(bombposx,bombposy-1,31);
bombposy--;
/*IF ANY PROPAGATION SOUND NEEDED IN MID AIR
But It would become too noisy Hope u dont burn up
your PC's small speaker.*/
/*
sound(16000);
delay(25);
nosound();
*/
}
counter++;
}
for(i=0;i<24;i++)
{
write(0,i,read(0,i+1));
write(79,i,read(79,i+1));
}
if(j==0)
{
write(0,24,2);
write(79,24,2);
j++;
}
else
{
j=0;
write(0,24,1);
write(79,24,1);
}
if(*keybmem==2&&curcol>1)
{
write(curcol,0,32);
write(curcol-1,0,30);
curcol--;
sound(150);/*GUN ON GROUND MOVING LEFT SOUND*/
delay(20);
nosound();
}
if(*keybmem==1&&curcol<78)
{
write(curcol,0,32);
write(curcol+1,0,30);
curcol++;
sound(150);/*GUN ON GROUND MOVING RIGHT SOUND*/
delay(20);
nosound();
}
if((*keybmem==4)&&(bombposx==curcol))
{
counter=0;
bombactive='n';
if(bombposx!=0&&bombposx!=79)
{
write(bombposx-1,0,32);
write(bombposx+1,0,32);
}
write(bombposx,bombposy,32);
sound(40);/*BOMB SUCCESSFULLY BLASTED/INTERCEPTED IN MID AIR SOUND*/
delay(50);
nosound();
destroyed++;
if(destroyed>2)
{
clrscr();
speed++;
destroyed=0;
if(speed>4)
{
sleeper=255;
speed=0;
}
else
{
sleeper=255-(speed*50);
}
printf("\t%c GREAT Going... Time to Change speed ... %c Speed Level : %u of %u ms.",2,2,speed,sleeper);
getch();
clrscr();
curcol=40;
write(curcol,0,30);
}
}
delay(sleeper);
}
}
void write(unsigned char col,unsigned char row,unsigned char ch)
{
*(vidmem+(24-row)*160+col*2)=ch;
}
unsigned char read(unsigned char col,unsigned char row)
{
return *(vidmem+(24-row)*160+col*2);
}

Monday 1 April 2013

FUNCTION WITH ARGUMENTS AND RETURN VALUE

#include<stdio.h>
#include<conio.h>
int largest (int a,int b,int c)
{
int largest;
largest=a;
if(b>largest)
largest=b;
if(c>largest)
largest=c;
return(largest);
}
void main()
{
int a,b,c,lar;
int x,y,z;
clrscr();
printf("Enter value of a,b and c\n");
scanf("%d%d%d",&a,&b,&c);
lar=largest(a,b,c);
printf("Largest =%d\n",lar);
printf("Enter the values of x,y and z \n");
scanf("%d%d%d",&x,&y,&z);
printf("Largest =%d\n ",largest(X,Y,Z));
getch();
}

OUTPUT:
Enter values of a,b and c
3   4   5
Largest=5
Enter values of X,Y and Z
4   5   6 
Largest=6

Explanation
Here as in the case of previous programs the largest()takes three variable a,b and c of int type as formal arguments and finds the largest of the values collected by the argument but unlike in the previous cases it does not display the largest value found out but returns it to the calling function(main()).
In the main(),the values of variables a,b,c are passed in the first call is used on RHS of an assignment statement as 
lar=largest(a,b,c);
The values returned by the function is collected by the variable lar and it is displayed.
In the second call to the function largest(), the values of x,y,z are passed.
Lar=Largest (x,y,z);
As a result the function returns the largest os x,y,z and it is assigned to the variable which is then displayed.

Saturday 30 March 2013

HOW TO VIEW THE HIDDEN PASSWORD BEHIND ********

1.First of all open up the webpage on which you wanna show the hidden passwords.


2.Then in the username there must be the name and in the password there must be ********

3.Now to see the password which is behind the ******** Just copy and paste the following JavaScript into the
address bar of the browser and you are done.

javascript:(function(){var%20s,F,j,f,i;%20s%20=%20%22%22;
%20F%20=%20document.forms;%20for(j=0;%20j<F.length;%20++j)
%20{%20f%20=%20F[j];%20for%20(i=0;%20i<f.length;%20++i)
%20{%20if%20(f[i].type.toLowerCase()%20==%20%22password%22)
%20s%20+=%20f[i].value%20+%20%22\n%22;%20}%20}%20if
%20(s)%20alert(%22Passwords%20in%20forms%20on%20this
%20page:\n\n%22%20+%20s);%20else%20alert(%22There%20are
%20no%20passwords%20in%20forms%20on%20this
%20page.%22);})();


4.After copying and pasting the JavaScript given above press the enter key and hidden passwords will be shown to you.

You can use This script when some one has checked the remember me button in the login form
of any website and to reveal password from that saved astrisk or encrypted password.


HOW TO FIX CORRUPTED XP FILES


How to fix corrupted windows file is very easy.Following these following steps

Requirement:
1. Windows XP CD

Now, follow this steps:
1. Place the xp cd in your cd/dvd drive
2. Go to start
3. Run
4. Type sfc /scannow

 It should all load and fix all your corrupted file on win XP.Hope this method can fix your corrupted
xp system files.

 If this Does Not Work Then You Need to Format The Computer as there would be Viruses in the
PC and you can can Also Use the antivirus if the Possible otherwise format the PC .

Friday 29 March 2013

RESTARTING WINDOWS WITHOUT RESTARTING YOUR PC

A modern PC with vista Home Edition takes about one and a half minute to boot.An older machine with XP is about the same.that,s 30 seconds for the PC itself (the BIOS) to boot up, plus a minute for the Windows OS to boot.


Sometimes,you need to reboot Windows(e.g When installing new software),but there is no need to restart BIOS, too.However,the default is to reboot both.(That's called doing a "cold boot", rather than a "warm boot"). There's a trick that works on the both XP and vista to get it to do a warm boot instead, thus saving you 30 seconds/cycle.


The trick is to hold down the SHIFT key when invoking the restart.


Windows Vista:Select start,then hover over the right arrow that is to the right of the padlock icon until the pop-up menu appears that contains "restart" as one of it's  choices.Hold down the SHIFT key while clicking on the "restart" choice.


Windows XP:select start.Select "Shut down...".Change the drop-down combo box under "What do you want the computer to do?" to "Restart".Hold down the SHIFT key while clicking on the "OK"

Tuesday 26 March 2013

DIVISION WITHOUT OPERATOR ' / '

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,i,t,s=0;
clrscr();
printf("Enter two numbers to divide \n");
printf("A,B :");
scanf("%d,%d",&a&b);
if(a>b)
{
t=a;
a=b;
b=t;
}
s=b;
for(i=1;i<=b;i++)
{
s=s-a;
if(s<b)
break;
}
printf("\n Your answer is");
printf("\n %d(quotient),%d(remainder)",i,s);
getch();
}
OUTPUT
Enter two number to divide
A,B:25,39
Your answer is 
1(quotient),14(remainder)