My Blog

My WordPress Blog

My Blog

My WordPress Blog

Month: September 2024

Write a Program to Calculate the Length of the String Using Recursion

C++// C++ Program for calculating // the length of string #include <iostream> using namespace std; int cal(char* str) { // base condition if (*str == ‘\0’) return 0; else return 1 + cal(str + 1); } int main() { char str[] = “GeeksforGeeks”; cout << cal(str); return 0; } Output

Write a Program to Check if the Given String is Palindrome or not Using Recursion

C++// C++ program to check // Whether a given number // Is palindrome or not #include <bits/stdc++.h> using namespace std; bool isPalRec(char str[], int s, int n) { // If there is only one character if (s == n) return true; // If first and last // characters do not match if (str[s] != str[n]) […]

Write a C++ Program to Print the Given String in Reverse Order Using Recursion

C++// C++ Program to // Reverse string using // recursion #include <iostream> using namespace std; void reverse_str(string& s, int n, int i) { if (n <= i) { return; } swap(s[i], s[n]); reverse_str(s, n – 1, i + 1); } int main() { string str = “GeeksforGeeks”; reverse_str(str, str.length() – 1, 0); cout << str […]

Write a Program to Print the Given String in Reverse Order 

C++// C++ Program to reversea string #include <cstring> #include <iostream> using namespace std; int main() { int len; string str = “GeeksforGeeks”; len = str.size(); cout << “Reverse of the string: “; for (int i = len – 1; i >= 0; i–) { cout << str[i]; } cout << endl; return 0; } Output

Scroll to top