why its repeating again my outputv
Https://ide.codingblocks.com/s/261946
hello @Aditya-Kushwaha-914550392281281
ur function is just printing the given string.
in this problem u will be given one string and u have to write a function that takes this string as input and returns an integer.
Approach: Write a recursive function that will take the first digit of the string and multiply it with the appropriate power of 10 and then add the recursive result for the substring starting at the second index. The termination condition will be when the passed string consists of a single digit. In that case, return the digit represented by the string.
// C++ implementation of the approach
#include<bits/stdc++.h>
using namespace std;
// Recursive function to convert
// string to integer
int stringToInt(string str)
{
// If the number represented as a string
// contains only a single digit
// then returns its value
if (str.length() == 1)
return (str[0] - '0');
// Recursive call for the sub-string
// starting at the second character
double y = stringToInt(str.substr(1));
// First digit of the number
double x = str[0] - '0';
// First digit multiplied by the
// appropriate power of 10 and then
// add the recursive result
// For example, xy = ((x * 10) + y)
x = x * pow(10, str.length() - 1) + y;
return int(x);
}
// Driver code
int main()
{
string str = "1235";
cout << (stringToInt(str)) << endl;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.