codeparrot/xlcost-text-to-code huggingface dataset:
Count unordered pairs ( i , j ) such that product of a [ i ] and a [ j ] is power of two | Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Function to Count unordered pairs ; is a number can be expressed as power of two ; count total number of unordered pairs ; Driver code
function isPowerOfTwo ( x ) { return ( x > 0 && ( ! ( ( x & ( x - 1 ) ) > 0 ) ) ) ; } function Count_pairs ( a , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPowerOfTwo ( a [ i ] ) ) count ++ ; } let ans = ( count * ( count - 1 ) ) / 2 ; document . write ( ans ) ; } let a = [ 2 , 5 , 8 , 16 , 128 ] ; let n = a . length ; Count_pairs ( a , n ) ;
Ways of dividing a group into two halves such that two elements are in different groups | This function will return the factorial of a given number ; This function will calculate nCr of given n and r ; This function will Calculate number of ways ; Driver Code
function factorial ( n ) { let result = 1 ; for ( let i = 1 ; i <= n ; i ++ ) result = result * i ; return result ; } function nCr ( n , r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } function calculate_result ( n ) { let result = 2 * nCr ( ( n - 2 ) , ( n / 2 - 1 ) ) ; return result ; } let a = 2 ; let b = 4 ; document . write ( calculate_result ( 2 * a ) + " " ) ; document . write ( calculate_result ( 2 * b ) + " " ) ;
Print values of ' a ' in equation ( a + b ) <= n and a + b is divisible by x | function to Find values of a , in equation ( a + b ) <= n and a + b is divisible by x . ; least possible which is divisible by x ; run a loop to get required answer ; increase value by x ; answer is possible ; Driver code ; function call
function PossibleValues ( b , x , n ) { let leastdivisible = ( Math . floor ( b / x ) + 1 ) * x ; let flag = 1 ; while ( leastdivisible <= n ) { if ( leastdivisible - b >= 1 ) { document . write ( leastdivisible - b + " " ) ; leastdivisible += x ; flag = 0 ; } else break ; } if ( flag > 0 ) document . write ( - 1 + " " ) ; } let b = 10 , x = 6 , n = 40 ; PossibleValues ( b , x , n ) ;
Check if all sub | Function to calculate product of digits between given indexes ; Function to check if all sub - numbers have distinct Digit product ; Length of number N ; Digit array ; to maintain digit products ; Finding all possible subarrays ; Driver code
function digitProduct ( digits , start , end ) { let pro = 1 ; for ( let i = start ; i <= end ; i ++ ) { pro *= digits [ i ] ; } return pro ; } function isDistinct ( N ) { let s = " " ; let len = s . length ; let digits = new Array ( ) ; let products = new Array ( ) ; for ( let i = 0 ; i < len ; i ++ ) { digits [ i ] = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } for ( let i = 0 ; i < len ; i ++ ) { for ( let j = i ; j < len ; j ++ ) { let val = digitProduct ( digits , i , j ) ; if ( products . includes ( val ) ) return false ; else products . push ( val ) ; } } return true ; } let N = 324 ; if ( isDistinct ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Hilbert Number | Utility function to return Nth Hilbert Number ; Driver code
function nthHilbertNumber ( n ) { return 4 * ( n - 1 ) + 1 ; } var n = 5 ; document . write ( nthHilbertNumber ( n ) ) ;
Program to find the nth Kynea number | Function to calculate nth kynea number ; Firstly calculate 2 ^ n + 1 ; Now calculate ( 2 ^ n + 1 ) ^ 2 ; Now calculate ( ( 2 ^ n + 1 ) ^ 2 ) - 2 ; return nth Kynea number ; Driver Code ; print nth kynea number
function nthKyneaNumber ( n ) { n = ( 1 << n ) + 1 ; n = n * n ; n = n - 2 ; return n ; } let n = 8 ; document . write ( nthKyneaNumber ( n ) ) ;
Program to find the nth Kynea number | Function to calculate nth kynea number ; Calculate nth kynea number ; Driver Code ; print nth kynea number
function nthKyneaNumber ( n ) { return ( ( 1 << ( 2 * n ) ) + ( 1 << ( n + 1 ) ) - 1 ) ; } let n = 2 ; document . write ( nthKyneaNumber ( n ) ) ;
Program to check whether a number is Proth number or not | Utility function to check power of two ; Function to check if the Given number is Proth number or not ; Check if k divides n or not ; Check if n / k is power of 2 or not ; Update k to next odd number ; If we reach here means there exists no value of K Such that k is odd number and n / k is a power of 2 greater than k ; Get n ; Check n for Proth Number
function isPowerOfTwo ( n ) { return ( n && ! ( n & ( n - 1 ) ) ) ; } function isProthNumber ( n ) { let k = 1 ; while ( k < parseInt ( n / k ) ) { if ( n % k == 0 ) { if ( isPowerOfTwo ( parseInt ( n / k ) ) ) return true ; } k = k + 2 ; } return false ; } let n = 25 ; if ( isProthNumber ( n - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find last two digits of sum of N factorials | Function to find the unit ' s ▁ and ▁ ten ' s place digit ; Let us write for cases when N is smaller than or equal to 10. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ... + 10 ! ) % 100 = 13 else ( N >= 10 ) ; Driver code
function get_last_two_digit ( N ) { if ( N <= 10 ) { let ans = 0 , fac = 1 ; for ( let i = 1 ; i <= N ; i ++ ) { fac = fac * i ; ans += fac ; } return ans % 100 ; } return 13 ; } let N = 1 ; for ( N = 1 ; N <= 10 ; N ++ ) document . write ( " " + N + " " + get_last_two_digit ( N ) + " " ) ;
Check whether product of ' n ' numbers is even or odd | function to check whether product of ' n ' numbers is even or odd ; if a single even number is found , then final product will be an even number ; product is an odd number ; Driver program to test above
function isProductEven ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) if ( ( arr [ i ] & 1 ) == 0 ) return true ; return false ; } let arr = [ 2 , 4 , 3 , 5 ] ; let n = arr . length ; if ( isProductEven ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Sum of squares of Fibonacci numbers | Function to calculate sum of squares of Fibonacci numbers ; Initialize result ; Add remaining terms ; Driver code
function calculateSquareSum ( n ) { if ( n <= 0 ) return 0 ; var fibo = Array ( n + 1 ) . fill ( 0 ) ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; var sum = ( fibo [ 0 ] * fibo [ 0 ] ) + ( fibo [ 1 ] * fibo [ 1 ] ) ; for ( i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; sum += ( fibo [ i ] * fibo [ i ] ) ; } return sum ; } var n = 6 ; document . write ( " " + calculateSquareSum ( n ) ) ;
Value of the series ( 1 ^ 3 + 2 ^ 3 + 3 ^ 3 + ... + n ^ 3 ) mod 4 for a given n | Function for obtaining the value of f ( n ) mod 4 ; Find the remainder of n when divided by 4 ; If n is of the form 4 k or 4 k + 3 ; If n is of the form 4 k + 1 or 4 k + 2 ; Driver Code
function fnMod ( n ) { var rem = n % 4 ; if ( rem == 0 rem == 3 ) return 0 ; else if ( rem == 1 rem == 2 ) return 1 ; return 0 ; } var n = 6 ; document . write ( fnMod ( n ) ) ;
Minimum increment operations to make the array in increasing order | Function to find minimum moves required to make the array in increasing order ; To store answer ; Tterate over an array ; Non - increasing order ; Add moves to answer ; Increase the element ; Return required answer ; Driver code
function MinimumMoves ( a , n , x ) { var ans = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= a [ i - 1 ] ) { var p = parseInt ( ( a [ i - 1 ] - a [ i ] ) / x + 1 ) ; ans += p ; a [ i ] += p * x ; } } return ans ; } var arr = [ 1 , 3 , 3 , 2 ] ; var x = 2 ; var n = arr . length ; document . write ( MinimumMoves ( arr , n , x ) ) ;
Check if a large number is divisible by 2 , 3 and 5 or not | Function to return sum of digits of a number ; Function to Check if a large number is divisible by 2 , 3 and 5 or not ; Driver code
function SumOfDigits ( str , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += ( str . charAt ( i ) - ' ' ) ; return sum ; } function Divisible ( str , n ) { if ( SumOfDigits ( str , n ) % 3 == 0 && str . charAt ( n - 1 ) == ' ' ) return true ; return false ; } var str = " " ; var n = str . length ; if ( Divisible ( str , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Count all the numbers in a range with smallest factor as K | Function to check if k is a prime number or not ; Corner case ; Check from 2 to n - 1 ; Function to check if a number is not divisible by any number between 2 and K - 1 ; to check if the num is divisible by any numbers between 2 and k - 1 ; if not divisible by any number between 2 and k - 1 but divisible by k ; Function to find count of numbers in range [ a , b ] with smallest factor as K ; a number can be divisible only by k and not by any number less than k only if k is a prime ; to check if a number has smallest factor as K ; Driver code
function isPrime ( k ) { if ( k <= 1 ) return false ; for ( let i = 2 ; i < k ; i ++ ) if ( k % i == 0 ) return false ; return true ; } function check ( num , k ) { let flag = 1 ; for ( let i = 2 ; i < k ; i ++ ) { if ( num % i == 0 ) flag = 0 ; } if ( flag == 1 ) { if ( num % k == 0 ) return 1 ; else return 0 ; } else return 0 ; } function findCount ( a , b , k ) { let count = 0 ; if ( ! isPrime ( k ) ) return 0 ; else { let ans ; for ( let i = a ; i <= b ; i ++ ) { ans = check ( i , k ) ; if ( ans == 1 ) count ++ ; else continue ; } } return count ; } let a = 2020 , b = 6300 , k = 29 ; document . write ( findCount ( a , b , k ) ) ;
Find the k | Function to find the k 'th divisor ; initialize vectors v1 and v2 ; store all the divisors in the two vectors accordingly ; reverse the vector v2 to sort it in increasing order ; if k is greater than the size of vectors then no divisor can be possible ; else print the ( k - 1 ) th value of vector ; If K is lying in first vector ; If K is lying in second vector ; Driver code
function findkth ( n , k ) { let v1 = [ ] ; let v2 = [ ] ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v1 . push ( i ) ; if ( i != Math . sqrt ( n ) ) v2 . push ( n / i ) ; } } v2 . reverse ( ) ; if ( k > ( v1 . length + v2 . length ) ) document . write ( " " ) ; else { if ( k <= v1 . length ) document . write ( v1 [ k - 1 ] ) ; else document . write ( v2 [ k - v1 . length - 1 ] ) ; } } let n = 15 , k = 2 ; findkth ( n , k ) ;
Number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y are integers | function to Find the number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y integers . ; to store answer ; iterate explicitly over all possible values of x ; return answer ; Driver Code ; function call
function NumberOfSolutions ( a , b , c , d ) { let ans = 0 ; for ( let i = a ; i <= b ; i ++ ) if ( d >= Math . max ( c , i + 1 ) ) ans += d - Math . max ( c , i + 1 ) + 1 ; return ans ; } let a = 2 , b = 3 , c = 3 , d = 4 ; document . write ( NumberOfSolutions ( a , b , c , d ) ) ;
Minimum value possible of a given function from the given set | Function to find the value of F ( n ) ; Driver code
function findF_N ( n ) { var ans = 0 ; for ( var i = 0 ; i < n ; ++ i ) ans += ( i + 1 ) * ( n - i - 1 ) ; return ans ; } var n = 3 ; document . write ( findF_N ( n ) ) ;
Find N digits number which is divisible by D | Function to return N digits number which is divisible by D ; to store answer ; Driver code
function findNumber ( n , d ) { let ans = " " ; if ( d != 10 ) { ans += ( d ) . toString ( ) ; for ( let i = 1 ; i < n ; i ++ ) ans += ' ' ; } else { if ( n == 1 ) ans += " " ; else { ans += ' ' ; for ( let i = 1 ; i < n ; i ++ ) ans += ' ' ; } } return ans ; } let n = 12 , d = 3 ; document . write ( findNumber ( n , d ) ) ;
Count all the numbers less than 10 ^ 6 whose minimum prime factor is N | Javascript implementation of above approach ; the sieve of prime number and count of minimum prime factor ; form the prime sieve ; 1 is not a prime number ; form the sieve ; if i is prime ; if i is the least prime factor ; mark the number j as non prime ; count the numbers whose least prime factor is i ; form the sieve ; display ; display
var MAX = 1000000 ; var sieve_Prime = Array . from ( { length : MAX + 4 } , ( _ , i ) => 0 ) ; var sieve_count = Array . from ( { length : MAX + 4 } , ( _ , i ) => 0 ) ; function form_sieve ( ) { sieve_Prime [ 1 ] = 1 ; for ( i = 2 ; i <= MAX ; i ++ ) { if ( sieve_Prime [ i ] == 0 ) { for ( j = i * 2 ; j <= MAX ; j += i ) { if ( sieve_Prime [ j ] == 0 ) { sieve_Prime [ j ] = 1 ; sieve_count [ i ] ++ ; } } } } } form_sieve ( ) ; var n = 2 ; document . write ( " " + ( sieve_count [ n ] + 1 ) ) ; n = 3 ; document . write ( " " + ( sieve_count [ n ] + 1 ) ) ;
How to access elements of a Square Matrix | Javascript Program to read a square matrix and print the elements on secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements on secondary diagonal ; Check for elements on secondary diagonal
let matrix = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { matrix [ i ] = new Array ( 5 ) ; for ( let j = 0 ; j < 5 ; j ++ ) { matrix [ i ] [ j ] = 0 ; } } let row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } document . write ( " " ) ; } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) == size - 1 ) document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } }
How to access elements of a Square Matrix | JavaScript Program to read a square matrix and print the elements above secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements above secondary diagonal ; check for elements above secondary diagonal
let matrix = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { matrix [ i ] = new Array ( 5 ) ; } let row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { document . write ( " " , matrix [ row_index ] [ column_index ] ) ; } document . write ( " " ) ; } document . write ( " " + " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) < size - 1 ) document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } }
Find the largest good number in the divisors of given number N | function to return distinct prime factors ; to store distinct prime factors ; run a loop upto sqrt ( n ) ; place this prime factor in vector ; This condition is to handle the case when n is a prime number greater than 1 ; function that returns good number ; distinct prime factors ; to store answer ; product of all distinct prime factors is required answer ; Driver code ; function call
function PrimeFactors ( n ) { let v = [ ] ; let x = n ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( x % i == 0 ) { v . push ( i ) ; while ( x % i == 0 ) x = Math . floor ( x / i ) ; } } if ( x > 1 ) v . push ( x ) ; return v ; } function GoodNumber ( n ) { let v = PrimeFactors ( n ) ; let ans = 1 ; for ( let i = 0 ; i < v . length ; i ++ ) ans *= v [ i ] ; return ans ; } let n = 12 ; document . write ( GoodNumber ( n ) ) ;
Find Largest Special Prime which is less than or equal to a given number | Function to check whether the number is a special prime or not ; While number is not equal to zero ; If the number is not prime return false . ; Else remove the last digit by dividing the number by 10. ; If the number has become zero then the number is special prime , hence return true ; Function to find the Largest Special Prime which is less than or equal to a given number ; Initially all numbers are considered Primes . ; There is always an answer possible ; Checking if the number is a special prime or not ; If yes print the number and break the loop . ; Else decrement the number . ; Driver code
function checkSpecialPrime ( sieve , num ) { while ( num != 0 ) { if ( ! sieve [ num ] ) { return false ; } num = Math . floor ( num / 10 ) ; } return true ; } function findSpecialPrime ( N ) { let sieve = new Array ( N + 10 ) ; sieve [ 0 ] = sieve [ 1 ] = false ; for ( let i = 0 ; i < N + 10 ; i ++ ) sieve [ i ] = true ; for ( let i = 2 ; i <= N ; i ++ ) { if ( sieve [ i ] ) { for ( let j = i * i ; j <= N ; j += i ) { sieve [ j ] = false ; } } } while ( true ) { if ( checkSpecialPrime ( sieve , N ) ) { document . write ( N + " " ) ; break ; } else N -- ; } } findSpecialPrime ( 379 ) ; findSpecialPrime ( 100 ) ;
Check if an integer can be expressed as a sum of two semi | Javascript Code to check if an integer can be expressed as sum of two semi - primes ; Utility function to compute semi - primes in a range ; num /= j , ++ cnt ; Increment count of prime numbers ; If number is greater than 1 , add it to the count variable as it indicates the number remain is prime number ; if count is equal to '2' then number is semi - prime ; Utility function to check if a number sum of two semi - primes ; arr [ i ] is already a semi - prime if n - arr [ i ] is also a semi - prime then we a number can be expressed as sum of two semi - primes ; Driver code
var MAX = 1000000 ; var arr = [ ] ; var sprime = Array ( MAX ) . fill ( false ) ; function computeSemiPrime ( ) { for ( var i = 2 ; i < MAX ; i ++ ) { var cnt = 0 ; var num = i ; for ( var j = 2 ; cnt < 2 && j * j <= num ; ++ j ) { while ( num % j == 0 ) { } } if ( num > 1 ) ++ cnt ; if ( cnt == 2 ) { sprime [ i ] = true ; arr . push ( i ) ; } } } function checkSemiPrime ( n ) { var i = 0 ; while ( arr [ i ] <= parseInt ( n / 2 ) ) { if ( sprime [ n - arr [ i ] ] ) { return true ; } i ++ ; } return false ; } computeSemiPrime ( ) ; var n = 30 ; if ( checkSemiPrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Check if a number is a Pythagorean Prime or not | Function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Driver Program ; Check if number is prime and of the form 4 * n + 1
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } var n = 13 ; if ( isPrime ( n ) && ( n % 4 == 1 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Divide an isosceles triangle in two parts with ratio of areas as n : m | Function to return the height ; type cast the n , m into float ; calculate the height for cut ; Driver code
function heightCalculate ( H , n , m ) { let N = n * 1.0 ; let M = m * 1.0 ; let h = H * Math . sqrt ( N / ( N + M ) ) ; return h ; } let H = 10 , n = 3 , m = 4 ; document . write ( heightCalculate ( H , n , m ) ) ;
Check n ^ 2 | Check if a number is prime or not ; Run a loop upto square of given number ; Check if n ^ 2 - m ^ 2 is prime ; Driver Code
function isprime ( x ) { for ( var i = 2 ; i * i <= x ; i ++ ) if ( x % i == 0 ) return false ; return true ; } function isNSqMinusnMSqPrime ( m , n ) { if ( n - m == 1 && isprime ( m + n ) ) return true ; else return false ; } var m = 13 , n = 16 ; if ( isNSqMinusnMSqPrime ( m , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find ' N ' number of solutions with the given inequality equations | Function to calculate all the solutions ; there is no solutions ; print first element as y - n + 1 ; print rest n - 1 elements as 1 ; initialize the number of elements and the value of x an y
function findsolution ( n , x , y ) { if ( ( y - n + 1 ) * ( y - n + 1 ) + n - 1 < x y < n ) { document . write ( " " ) ; return ; } document . write ( y - n + 1 ) ; while ( n -- > 1 ) document . write ( " " + 1 ) ; } let n = 5 ; let x = 15 ; let y = 15 ; findsolution ( n , x , y ) ;
Number of different positions where a person can stand | Function to find the position ; Driver code
function findPosition ( n , f , b ) { return n - Math . max ( f + 1 , n - b ) + 1 ; } let n = 5 , f = 2 , b = 3 ; document . write ( findPosition ( n , f , b ) ) ;
Program for n | Function to find the nth odd number ; Driver code
function nthOdd ( n ) { return ( 2 * n - 1 ) ; } var n = 10 ; document . write ( nthOdd ( n ) ) ;
Program to find the Nth Harmonic Number | Function to find N - th Harmonic Number ; H1 = 1 ; loop to apply the forumula Hn = H1 + H2 + H3 ... + Hn - 1 + Hn - 1 + 1 / n ; Driver Code
function nthHarmonic ( N ) { let harmonic = 1.00 ; for ( let i = 2 ; i <= N ; i ++ ) { harmonic += parseFloat ( 1 ) / i ; } return harmonic ; } let N = 8 ; document . write ( nthHarmonic ( N ) . toFixed ( 5 ) ) ;
Program to find Nth term of series 0 , 7 , 18 , 33 , 51 , 75 , 102 , 133 , ... . . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 2 * Math . pow ( n , 2 ) + n - 3 ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Program to find Nth term of series 0 , 10 , 30 , 60 , 99 , 150 , 210 , 280. ... ... ... . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 5 * Math . pow ( n , 2 ) - 5 * n ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Program to find Nth term of series 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 3 * Math . pow ( n , 2 ) + n - 2 ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Program to find Nth term of series 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 2 * Math . pow ( n , 2 ) + 4 * n - 2 ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Program to find Nth term of series 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203 , ... . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 3 * Math . pow ( n , 2 ) + 2 * n - 5 ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Program to find Nth term of series 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147 , ... . . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 2 * Math . pow ( n , 2 ) + 3 * n - 5 ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Program to find Nth term of series 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . | calculate Nth term of series ; Driver code
function nthTerm ( n ) { return 4 * Math . pow ( n , 2 ) - 3 * n + 2 ; } let N = 4 ; document . write ( nthTerm ( N ) ) ;
Find other two sides and angles of a right angle triangle | Javascript program to print all sides and angles of right angle triangle given one side ; Function to find angle A Angle in front of side a ; applied cosine rule ; convert into degrees ; Function to find angle B Angle in front of side b ; applied cosine rule ; convert into degrees and return ; Function to print all angles of the right angled triangle ; for calculate angle A ; for calculate angle B ; Function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Print angles of the triangle ; Driver Code
let PI = 3.1415926535 ; function findAnglesA ( a , b , c ) { let A = Math . acos ( ( b * b + c * c - a * a ) / ( 2 * b * c ) ) ; return A * 180 / PI ; } function findAnglesB ( a , b , c ) { let B = Math . acos ( ( a * a + c * c - b * b ) / ( 2 * a * c ) ) ; return B * 180 / PI ; } function printAngles ( a , b , c ) { let x = a ; let y = b ; let z = c ; let A = findAnglesA ( x , y , z ) ; let B = findAnglesB ( x , y , z ) ; document . write ( " " + A + " " + B + " " + 90 ) ; } function printOtherSides ( n ) { let b = 0 , c = 0 ; if ( ( n & 1 ) > 0 ) { if ( n == 1 ) document . write ( - 1 ) ; else { b = ( n * n - 1 ) / 2 ; c = ( n * n + 1 ) / 2 ; document . write ( " " + b + " " + c ) ; } } else { if ( n == 2 ) document . write ( - 1 ) ; else { b = n * n / 4 - 1 ; c = n * n / 4 + 1 ; document . write ( " " + b + " " + c + " " ) ; } } printAngles ( n , b , c ) ; } let a = 12 ; printOtherSides ( a ) ;