codeparrot/xlcost-text-to-code huggingface dataset:
Find out the correct position of the ball after shuffling | C ++ implementation of the above approach ; Function to generate the index of the glass containing the ball ; Change the index ; Change the index ; Print the index ; Driver 's Code ; Storing all the shuffle operation
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int M = 3 , N = 2 ; void getIndex ( int n , int shuffle [ ] [ N ] ) { for ( int i = 0 ; i < 3 ; i ++ ) { if ( shuffle [ i ] [ 0 ] == n ) n = shuffle [ i ] [ 1 ] ; else if ( shuffle [ i ] [ 1 ] == n ) n = shuffle [ i ] [ 0 ] ; } cout << n ; } int main ( ) { int n = 3 ; int shuffle [ M ] [ N ] = { { 3 , 1 } , { 2 , 1 } , { 1 , 2 } } ; getIndex ( n , shuffle ) ; }
Count the number of subsequences of length k having equal LCM and HCF | C ++ implementation ; Returns factorial of n ; Returns nCr for the given values of r and n ; Map to store the frequencies of each elements ; Loop to store the frequencies of elements in the map ; Using nCR formula to calculate the number of subsequences of a given length ; Driver Code ; Function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long fact ( int n ) { long long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } long long nCr ( int n , int r ) { return fact ( n ) / ( 1LL * fact ( r ) * fact ( n - r ) ) ; } long long number_of_subsequences ( int arr [ ] , int k , int n ) { long long s = 0 ; map < int , int > m ; for ( int i = 0 ; i < n ; i ++ ) { m [ arr [ i ] ] ++ ; } for ( auto j : m ) { s = s + 1LL * nCr ( j . second , k ) ; } return s ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 1 , 2 , 2 , 2 } ; int k = 2 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << number_of_subsequences ( arr , k , n ) ; return 0 ; }
Find the sum of all possible pairs in an array of N elements | C ++ implementation of the approach ; Function to return the sum of the elements of all possible pairs from the array ; To store the required sum ; For every element of the array ; It appears ( 2 * n ) times ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sumPairs ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ( arr [ i ] * ( 2 * n ) ) ; } return sum ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << sumPairs ( arr , n ) ; return 0 ; }
Minimum sum obtained from groups of four elements from the given array | C ++ implementation of the approach ; Function to return the minimum required sum ; To store the required sum ; Sort the array in descending order ; The indices which give 0 or 1 as the remainder when divided by 4 will be the maximum two elements of the group ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minSum ( int arr [ ] , int n ) { int sum = 0 ; sort ( arr , arr + n , greater < int > ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 4 < 2 ) sum = sum + arr [ i ] ; } return sum ; } int main ( ) { int arr [ ] = { 1 , 1 , 10 , 2 , 2 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minSum ( arr , n ) ; return 0 ; }
Count of triples ( A , B , C ) where A * C is greater than B * B | C ++ implementation ; function to return the count of the valid triplets ; Driver Code ; function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long countTriplets ( int A , int B , int C ) { long long ans = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { for ( int j = 1 ; j <= B ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { if ( i * k > j * j ) ans ++ ; } } } return ans ; } int main ( ) { int A , B , C ; A = 3 , B = 2 , C = 2 ; cout << countTriplets ( A , B , C ) ; }
Count of triples ( A , B , C ) where A * C is greater than B * B | C ++ implementation ; Counts the number of triplets for a given value of b ; Count all triples in which a = i ; Smallest value j such that i * j > B2 ; Count all ( i , B2 , x ) such that x >= j ; count all ( x , B2 , y ) such that x >= j this counts all such triples in which a >= j ; As all triples with a >= j have been counted reduce A to j - 1. ; Counts the number of triples that satisfy the given constraints ; GetCount of triples in which b = i ; Driver Code ; Function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long getCount ( int A , int B2 , int C ) { long long count = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { long long j = ( B2 / i ) + 1 ; if ( C >= j ) count = ( count + C - j + 1 ) ; if ( A >= j && C >= i ) count = ( count + ( C - i + 1 ) * ( A - j + 1 ) ) ; if ( A >= j ) A = j - 1 ; } return count ; } long long countTriplets ( int A , int B , int C ) { long long ans = 0 ; for ( int i = 1 ; i <= B ; i ++ ) { ans = ( ans + getCount ( A , i * i , C ) ) ; } return ans ; } int main ( ) { int A , B , C ; A = 3 , B = 2 , C = 2 ; cout << countTriplets ( A , B , C ) ; }
Summation of floor of harmonic progression | C ++ implementation of the approach ; Function to return the summation of the given harmonic series ; To store the summation ; Floor of sqrt ( n ) ; Summation of floor ( n / i ) ; From the formula ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long int getSum ( int n ) { long long int sum = 0 ; int k = sqrt ( n ) ; for ( int i = 1 ; i <= k ; i ++ ) { sum += floor ( n / i ) ; } sum *= 2 ; sum -= pow ( k , 2 ) ; return sum ; } int main ( ) { int n = 5 ; cout << getSum ( n ) ; return 0 ; }
Count of distinct remainders when N is divided by all the numbers from the range [ 1 , N ] | C ++ implementation of the approach ; Function to return the count of distinct remainders that can be obtained when n is divided by every element from the range [ 1 , n ] ; If n is even ; If n is odd ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int distinctRemainders ( int n ) { if ( n % 2 == 0 ) return ( n / 2 ) ; return ( 1 + ( n / 2 ) ) ; } int main ( ) { int n = 5 ; cout << distinctRemainders ( n ) ; return 0 ; }
Count total unset bits in all the numbers from 1 to N | C ++ implementation of the approach ; Function to return the count of unset bits in the binary representation of all the numbers from 1 to n ; To store the count of unset bits ; For every integer from the range [ 1 , n ] ; A copy of the current integer ; Count of unset bits in the current integer ; If current bit is unset ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countUnsetBits ( int n ) { int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int temp = i ; while ( temp ) { if ( temp % 2 == 0 ) cnt ++ ; temp = temp / 2 ; } } return cnt ; } int main ( ) { int n = 5 ; cout << countUnsetBits ( n ) ; return 0 ; }
Find if a degree sequence can form a simple graph | Havel | C ++ implementation of the approach ; Function that returns true if a simple graph exists ; Keep performing the operations until one of the stopping condition is met ; Sort the list in non - decreasing order ; Check if all the elements are equal to 0 ; Store the first element in a variable and delete it from the list ; Check if enough elements are present in the list ; Subtract first element from next v elements ; Check if negative element is encountered after subtraction ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool graphExists ( vector < int > & a , int n ) { while ( 1 ) { sort ( a . begin ( ) , a . end ( ) , greater < > ( ) ) ; if ( a [ 0 ] == 0 ) return true ; int v = a [ 0 ] ; a . erase ( a . begin ( ) + 0 ) ; if ( v > a . size ( ) ) return false ; for ( int i = 0 ; i < v ; i ++ ) { a [ i ] -- ; if ( a [ i ] < 0 ) return false ; } } } int main ( ) { vector < int > a = { 3 , 3 , 3 , 3 } ; int n = a . size ( ) ; graphExists ( a , n ) ? cout << " Yes " : cout << " NO " << endl ; return 0 ; }
Number of sub arrays with negative product | C ++ implementation of the approach ; Function to return the count of subarrays with negative product ; Replace current element with 1 if it is positive else replace it with - 1 instead ; Take product with previous element to form the prefix product ; Count positive and negative elements in the prefix product array ; Return the required count of subarrays ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int negProdSubArr ( int arr [ ] , int n ) { int positive = 1 , negative = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) arr [ i ] = 1 ; else arr [ i ] = -1 ; if ( i > 0 ) arr [ i ] *= arr [ i - 1 ] ; if ( arr [ i ] == 1 ) positive ++ ; else negative ++ ; } return ( positive * negative ) ; } int main ( ) { int arr [ ] = { 5 , -4 , -3 , 2 , -5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << negProdSubArr ( arr , n ) ; return ( 0 ) ; }
Repeated sum of first N natural numbers | C ++ implementation of the approach ; Function to return the sum of the first n natural numbers ; Function to return the repeated sum ; Perform the operation exactly k times ; Update n with the sum of first n natural numbers ; Driver code
#include <iostream> NEW_LINE using namespace std ; int sum ( int n ) { int sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } int repeatedSum ( int n , int k ) { for ( int i = 0 ; i < k ; i ++ ) { n = sum ( n ) ; } return n ; } int main ( ) { int n = 2 , k = 2 ; cout << repeatedSum ( n , k ) ; return 0 ; }
Difference between Sum of Cubes and Sum of First N Natural Numbers | C ++ program to find the difference between the sum of the cubes of the first N natural numbers and the sum of the first N natural number ; Sum of first n natural numbers ; Find the required difference ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int difference ( int n ) { int S , res ; S = ( n * ( n + 1 ) ) / 2 ; res = S * ( S - 1 ) ; return res ; } int main ( ) { int n = 5 ; cout << difference ( n ) ; return 0 ; }
Check if the sum of digits of number is divisible by all of its digits | C ++ implementation of the approach ; Function that returns true if all the digits of n divide the sum of the digits of n ; Store a copy of the original number ; Find the sum of the digits of n ; Restore the original value ; Check if all the digits divide the calculated sum ; If current digit doesn 't  divide the sum ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivisible ( long long int n ) { long long int temp = n ; int sum = 0 ; while ( n ) { int digit = n % 10 ; sum += digit ; n /= 10 ; } n = temp ; while ( n ) { int digit = n % 10 ; if ( sum % digit != 0 ) return false ; n /= 10 ; } return true ; } int main ( ) { long long int n = 123 ; if ( isDivisible ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Program for Mobius Function | Set 2 | C ++ implementation of the approach ; Function to calculate least prime factor of each number ; If it is a prime number ; For all multiples which are not visited yet . ; Function to find the value of Mobius function for all the numbers from 1 to n ; To store the values of Mobius function ; If number is one ; If number has a squared prime factor ; Multiply - 1 with the previous number ; Driver code ; Function to find least prime factor ; Function to find mobius function
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define N  100005 NEW_LINE int lpf [ N ] ; void least_prime_factor ( ) { for ( int i = 2 ; i < N ; i ++ ) if ( ! lpf [ i ] ) for ( int j = i ; j < N ; j += i ) if ( ! lpf [ j ] ) lpf [ j ] = i ; } void Mobius ( int n ) { int mobius [ N ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( i == 1 ) mobius [ i ] = 1 ; else { if ( lpf [ i / lpf [ i ] ] == lpf [ i ] ) mobius [ i ] = 0 ; else mobius [ i ] = -1 * mobius [ i / lpf [ i ] ] ; } } for ( int i = 1 ; i <= n ; i ++ ) cout << mobius [ i ] << " ▁ " ; } int main ( ) { int n = 5 ; least_prime_factor ( ) ; Mobius ( n ) ; }
Make the list non | C ++ implementation of the approach ; Function to return the minimum element from the range [ prev , MAX ] such that it differs in at most 1 digit with cur ; To start with the value we have achieved in the last step ; Store the value with which the current will be compared ; Current value ; There are at most 4 digits ; If the current digit differs in both the numbers ; Eliminate last digits in both the numbers ; If the number of different digits is at most 1 ; If we can 't find any number for which  the number of change is less than or  equal to 1 then return -1 ; Function to get the non - decreasing list ; Creating a vector for the updated list ; Let 's assume that it is possible to  make the list non-decreasing ; Element of the original array ; Can 't make the list non-decreasing ; If possible then print the list ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int DIGITS = 4 , MIN = 1000 , MAX = 9999 ; int getBest ( int prev , int cur ) { int maximum = max ( MIN , prev ) ; for ( int i = maximum ; i <= MAX ; i ++ ) { int cnt = 0 ; int a = i ; int b = cur ; for ( int k = 0 ; k < DIGITS ; k ++ ) { if ( a % 10 != b % 10 ) cnt += 1 ; a /= 10 ; b /= 10 ; } if ( cnt <= 1 ) return i ; } return -1 ; } void getList ( int arr [ ] , int n ) { vector < int > myList ; int i , cur ; bool possible = true ; myList . push_back ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { cur = arr [ i ] ; myList . push_back ( getBest ( myList . back ( ) , cur ) ) ; if ( myList . back ( ) == -1 ) { possible = false ; break ; } } if ( possible ) { for ( i = 1 ; i < myList . size ( ) ; i ++ ) cout << myList [ i ] << " ▁ " ; } else cout << " - 1" ; } int main ( ) { int arr [ ] = { 1095 , 1094 , 1095 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getList ( arr , n ) ; return 0 ; }
Maximum items that can be bought with the given type of coins | C ++ implementation of the approach ; Function to find maximum fruits Can buy from given values of x , y , z . ; Items of type 1 that can be bought ; Update the coins ; Items of type 2 that can be bought ; Update the coins ; Items of type 3 that can be bought ; Update the coins ; Items of type 4 that can be bought To buy a type 4 item , a coin of each type is required ; Total items that can be bought ; Driver code
#include <iostream> NEW_LINE using namespace std ; const int COST = 3 ; int maxItems ( int x , int y , int z ) { int type1 = x / COST ; x %= COST ; int type2 = y / COST ; y %= COST ; int type3 = z / COST ; z %= COST ; int type4 = min ( x , min ( y , z ) ) ; int maxItems = type1 + type2 + type3 + type4 ; return maxItems ; } int main ( ) { int x = 4 , y = 5 , z = 6 ; cout << maxItems ( x , y , z ) ; return 0 ; }
Count occurrences of a prime number in the prime factorization of every element from the given range | C ++ implementation of the approach ; Function to return the highest power of p that divides n ; Function to return the count of times p appears in the prime factors of the elements from the range [ l , r ] ; To store the required count ; For every element of the range ; Add the highest power of p that divides i ; Driver code
#include <iostream> NEW_LINE using namespace std ; int countFactors ( int n , int p ) { int pwr = 0 ; while ( n > 0 && n % p == 0 ) { n /= p ; pwr ++ ; } return pwr ; } int getCount ( int l , int r , int p ) { int cnt = 0 ; for ( int i = l ; i <= r ; i ++ ) { cnt += countFactors ( i , p ) ; } return cnt ; } int main ( ) { int l = 2 , r = 8 , p = 2 ; cout << getCount ( l , r , p ) ; return 0 ; }
Count occurrences of a prime number in the prime factorization of every element from the given range | C ++ implementation of the approach ; Function to return the count of times p appears in the prime factors of the elements from the range [ l , r ] ; To store the required count ; Number of values in the range [ 0 , r ] that are divisible by val ; Number of values in the range [ 0 , l - 1 ] that are divisible by val ; Increment the power of the val ; ( a - b ) is the count of numbers in the range [ l , r ] that are divisible by val ; No values that are divisible by val thus exiting from the loop ; Driver code
#include <iostream> NEW_LINE using namespace std ; int getCount ( int l , int r , int p ) { int cnt = 0 ; int val = p ; while ( 1 ) { int a = r / val ; int b = ( l - 1 ) / val ; val *= p ; if ( a - b ) { cnt += ( a - b ) ; } else break ; } return cnt ; } int main ( ) { int l = 2 , r = 8 , p = 2 ; cout << getCount ( l , r , p ) ; return 0 ; }
Check if the number is valid when flipped upside down | C ++ implementation of the approach ; Function that returns true if str is Topsy Turvy ; For every character of the string ; If the current digit cannot form a valid digit when turned upside - down ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool topsyTurvy ( string str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == '2' str [ i ] == '4' str [ i ] == '5' str [ i ] == '6' str [ i ] == '7' str [ i ] == '9' ) { return false ; } } return true ; } int main ( ) { string str = "1234" ; if ( topsyTurvy ( str ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Find the count of subsequences where each element is divisible by K | C ++ implementation of the approach ; Function to return the count of all valid subsequences ; To store the count of elements which are divisible by k ; If current element is divisible by k then increment the count ; Total ( 2 ^ n - 1 ) non - empty subsequences are possible with n element ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSubSeq ( int arr [ ] , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { count ++ ; } } return ( pow ( 2 , count ) - 1 ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; cout << countSubSeq ( arr , n , k ) ; return 0 ; }
Count of numbers below N whose sum of prime divisors is K | C ++ implementation of the approach ; Function to return the count of numbers below N whose sum of prime factors is K ; To store the sum of prime factors for all the numbers ; If i is prime ; Add i to all the numbers which are divisible by i ; To store the count of required numbers ; Return the required count ; Driver code
#include <iostream> NEW_LINE using namespace std ; #define MAX  1000001 NEW_LINE int countNum ( int N , int K ) { int sumPF [ MAX ] = { 0 } ; for ( int i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == 0 ) { for ( int j = i ; j < N ; j += i ) { sumPF [ j ] += i ; } } } int count = 0 ; for ( int i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == K ) count ++ ; } return count ; } int main ( ) { int N = 20 , K = 7 ; cout << countNum ( N , K ) ; return 0 ; }
Queries for the smallest and the largest prime number of given digit | C ++ implementation of the approach ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p greater than or equal to the square of it numbers which are multiple of p and are less than p ^ 2 are already been marked . ; Function to return the smallest prime number with d digits ; check if prime ; Function to return the largest prime number with d digits ; check if prime ; Driver code ; Perform queries
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  100000 NEW_LINE bool prime [ MAX + 1 ] ; void SieveOfEratosthenes ( ) { memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } } int smallestPrime ( int d ) { int l = pow ( 10 , d - 1 ) ; int r = pow ( 10 , d ) - 1 ; for ( int i = l ; i <= r ; i ++ ) { if ( prime [ i ] ) { return i ; } } return -1 ; } int largestPrime ( int d ) { int l = pow ( 10 , d - 1 ) ; int r = pow ( 10 , d ) - 1 ; for ( int i = r ; i >= l ; i -- ) { if ( prime [ i ] ) { return i ; } } return -1 ; } int main ( ) { SieveOfEratosthenes ( ) ; int queries [ ] = { 2 , 5 } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) { cout << smallestPrime ( queries [ i ] ) << " ▁ " << largestPrime ( queries [ i ] ) << endl ; } return 0 ; }
Find a Square Matrix such that sum of elements in every row and column is K | C ++ implementation of the approach ; Function to print the required matrix ; Print k for the left diagonal elements ; Print 0 for the rest ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printMatrix ( int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) cout << k << " ▁ " ; else cout << "0 ▁ " ; } cout << " STRNEWLINE " ; } } int main ( ) { int n = 3 , k = 7 ; printMatrix ( n , k ) ; return ( 0 ) ; }
Divide first N natural numbers into 3 equal sum subsets | C ++ implementation of the approach ; Function that returns true if the subsets are possible ; If n <= 3 then it is not possible to divide the elements in three subsets satisfying the given conditions ; Sum of all the elements in the range [ 1 , n ] ; If the sum is divisible by 3 then it is possible ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool possible ( int n ) { if ( n > 3 ) { int sum = ( n * ( n + 1 ) ) / 2 ; if ( sum % 3 == 0 ) { return true ; } } return false ; } int main ( ) { int n = 5 ; if ( possible ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Find the Nth element of the modified Fibonacci series | C ++ implementation of the approach ; Function to return the Nth number of the modified Fibonacci series where A and B are the first two terms ; To store the current element which is the sum of previous two elements of the series ; This loop will terminate when the Nth element is found ; Return the Nth element ; Driver code
#include <iostream> NEW_LINE using namespace std ; int findNthNumber ( int A , int B , int N ) { int sum = 0 ; for ( int i = 2 ; i < N ; i ++ ) { sum = A + B ; A = B ; B = sum ; } return sum ; } int main ( ) { int A = 5 , B = 7 , N = 10 ; cout << findNthNumber ( A , B , N ) ; return 0 ; }
Check if an array is increasing or decreasing | C ++ implementation of the approach ; Function to check the type of the array ; If the first two and the last two elements of the array are in increasing order ; If the first two and the last two elements of the array are in decreasing order ; If the first two elements of the array are in increasing order and the last two elements of the array are in decreasing order ; If the first two elements of the array are in decreasing order and the last two elements of the array are in increasing order ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkType ( int arr [ ] , int n ) { if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] <= arr [ n - 1 ] ) cout << " Increasing " ; else if ( arr [ 0 ] >= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) cout << " Decreasing " ; else if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) cout << " Increasing ▁ then ▁ decreasing " ; else cout << " Decreasing ▁ then ▁ increasing " ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; checkType ( arr , n ) ; return 0 ; }
Calculate the IST : Indian Standard Time | C ++ implementation of the approach ; Function to calculate Indian Standard Time ; Separate integer part ; Separate float part and return ceil value ; Driver code ; Number of hours ( 1 - 24 ) ; Rotations in degrees
#include <cmath> NEW_LINE #include <iostream> NEW_LINE using namespace std ; void cal_IST ( int h , float r ) { float IST = ( h * r * 1.0 ) / 360 ; int int_IST = ( int ) IST ; int float_IST = ceil ( ( IST - int_IST ) * 60 ) ; cout << int_IST << " : " << float_IST ; } int main ( ) { int h = 20 ; float r = 150 ; cal_IST ( h , r ) ; return 0 ; }