Modify characters of a string by adding integer values of same | C ++ program for the above approach ; Function to modify a given string by adding ASCII value of characters from a string S to integer values of same indexed characters in string N ; Traverse the string ; Stores integer value of character in string N ; Stores ASCII value of character in string S ; If b exceeds 122 ; Replace the character ; Print resultant string ; Driver Code ; Given strings ; Function call to modify string S by given operations
#include <bits/stdc++.h> NEW_LINE using namespace std ; void addASCII ( string S , string N ) { for ( int i = 0 ; i < S . size ( ) ; i ++ ) { int a = int ( N [ i ] ) - '0' ; int b = int ( S [ i ] ) + a ; if ( b > 122 ) b -= 26 ; S [ i ] = char ( b ) ; } cout << S ; } int main ( ) { string S = " sun " , N = "966" ; addASCII ( S , N ) ; return 0 ; }