codeparrot/xlcost-text-to-code huggingface dataset:
Pell Number | Pell Number Series using Recursion in C ; calculate nth pell number ; driver function
#include <stdio.h> NEW_LINE int pell ( int n ) { if ( n <= 2 ) return n ; return 2 * pell ( n - 1 ) + pell ( n - 2 ) ; } int main ( ) { int n = 4 ; printf ( " % d " , pell ( n ) ) ; return 0 ; }
Legendre 's formula (Given p and n, find the largest x such that p^x divides n!) | C program to find largest x such that p * x divides n ! ; Returns largest power of p that divides n ! ; Initialize result ; Calculate x = n / p + n / ( p ^ 2 ) + n / ( p ^ 3 ) + ... . ; Driver program
#include <stdio.h> NEW_LINE int largestPower ( int n , int p ) { int x = 0 ; while ( n ) { n /= p ; x += n ; } return x ; } int main ( ) { int n = 10 , p = 3 ; printf ( " The ▁ largest ▁ power ▁ of ▁ % d ▁ that ▁ divides ▁ % d ! ▁ is ▁ % d STRNEWLINE " , p , n , largestPower ( n , p ) ) ; return 0 ; }
Program for factorial of a number | C ++ program to find factorial of given number ; single line to find factorial ; Driver Code
#include <stdio.h> NEW_LINE int factorial ( int n ) { return ( n == 1 n == 0 ) ? 1 : n * factorial ( n - 1 ) ; } int main ( ) { int num = 5 ; printf ( " Factorial ▁ of ▁ % d ▁ is ▁ % d " , num , factorial ( num ) ) ; return 0 ; }
Extract ' k ' bits from a given position in a number . | C program to extract k bits from a given position . ; Function to extract k bits from p position and returns the extracted value as integer ; Driver code
#include <stdio.h> NEW_LINE int bitExtracted ( int number , int k , int p ) { return ( ( ( 1 << k ) - 1 ) & ( number >> ( p - 1 ) ) ) ; } int main ( ) { int number = 171 , k = 5 , p = 2 ; printf ( " The ▁ extracted ▁ number ▁ is ▁ % d " , bitExtracted ( number , k , p ) ) ; return 0 ; }
Largest gap in an array | A C program to find largest gap between two elements in an array . ; function to solve the given problem ; Driver Code
#include <limits.h> NEW_LINE #include <stdio.h> NEW_LINE #include <stdlib.h> NEW_LINE int solve ( int a [ ] , int n ) { int max1 = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( abs ( a [ i ] - a [ j ] ) > max1 ) { max1 = abs ( a [ i ] - a [ j ] ) ; } } } return max1 ; } int main ( ) { int arr [ ] = { -1 , 2 , 3 , -4 , -10 , 22 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " Largest ▁ gap ▁ is ▁ : ▁ % d " , solve ( arr , size ) ) ; return 0 ; }
Largest gap in an array | A C program to find largest gap between two elements in an array . ; function to solve the given problem ; finding maximum and minimum of an array ; Driver Code
#include <limits.h> NEW_LINE #include <stdio.h> NEW_LINE #include <stdlib.h> NEW_LINE int solve ( int a [ ] , int n ) { int min1 = a [ 0 ] ; int max1 = a [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > max1 ) max1 = a [ i ] ; if ( a [ i ] < min1 ) min1 = a [ i ] ; } return abs ( min1 - max1 ) ; } int main ( ) { int arr [ ] = { -1 , 2 , 3 , 4 , -10 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " Largest ▁ gap ▁ is ▁ : ▁ % d " , solve ( arr , size ) ) ; return 0 ; }