Count of possible subarrays and subsequences using given length of Array | C ++ implementation to count the subarray and subsequence of given length of the array ; Function to count the subarray for the given array ; Function to count the subsequence for the given array length ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSubarray ( int n ) { return ( ( n ) * ( n + 1 ) ) / 2 ; } int countSubsequence ( int n ) { return pow ( 2 , n ) ; } int main ( ) { int n = 5 ; cout << ( countSubarray ( n ) ) << endl ; cout << ( countSubsequence ( n ) ) << endl ; return 0 ; }