facebook

Showing posts with label simple c program example. Show all posts
Showing posts with label simple c program example. Show all posts

Friday, 1 February 2013

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