facebook

Showing posts with label c program help. Show all posts
Showing posts with label c program help. Show all posts

Friday, 1 February 2013

How to restart your computer, C restart



#define B_ADR (0xFFFF0000UL)// You point it at memory location 0xFFFF0000 which is where the cold boot function is located

#define R_ADR (0x00400072UL)

#define C_BOOT (0)
#define W_BOOT (1)
void Restart( int type )
{
void ((far *fp)()) = (void (far *)()) B_ADR;
if ( type==C_BOOT )
*(unsigned int far *) R_ADR = 0;
else
*(unsigned int far *) R_ADR = 0x1234;
(*fp)( );
}

Sample programs in c



Simple c programs



1)Factorial

long Fact ( int n )
{
if ( n>0 )
return( n * Fact (n-1) ); //recursion
else
return( 1 );
}

2) GCD
int GCD( int x, int y ) {
if ( x>=y AND x%y==0 )
return( y );
else if ( x
return( GCD( y, x ) );
else
return( GCD( y, x%y ) );
}