Find the character made by adding all the characters of the given string | C ++ implementation of the approach ; Function to return the required character ; To store the sum of the characters of the given string ; Add the current character to the sum ; Return the required character ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; char getChar ( string str ) { int sum = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { sum += ( str [ i ] - ' a ' + 1 ) ; } if ( sum % 26 == 0 ) return ' z ' ; else { sum = sum % 26 ; return ( char ) ( ' a ' + sum - 1 ) ; } } int main ( ) { string str = " gfg " ; cout << getChar ( str ) ; return 0 ; }