Count of total Heads and Tails after N flips in a coin | C ++ program to count total heads and tails after N flips in a coin ; Function to find count of head and tail ; Check if initially all the coins are facing towards head ; Check if initially all the coins are facing towards tail ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; pair < int , int > count_ht ( char s , int N ) { pair < int , int > p ; if ( s == ' H ' ) { p . first = floor ( N / 2.0 ) ; p . second = ceil ( N / 2.0 ) ; } else if ( s == ' T ' ) { p . first = ceil ( N / 2.0 ) ; p . second = floor ( N / 2.0 ) ; } return p ; } int main ( ) { char C = ' H ' ; int N = 5 ; pair < int , int > p = count_ht ( C , N ) ; cout << " Head ▁ = ▁ " << ( p . first ) << " STRNEWLINE " ; cout << " Tail ▁ = ▁ " << ( p . second ) << " STRNEWLINE " ; }