Question

Write a recursive function, vowels, that return the number Of vowels in a string. Also, write...

Write a recursive function, vowels, that return the number Of vowels in a string. Also, write a program to test your function. Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function. A palindrome is a string that reads the same both forward and backward. Write a program that uses recursive function to check whether a string is A palindrome. Your program must contain a value-returning recursive function that returns true if the String is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.

C++

Complete .cpp .h files

(C++)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of code:

output:

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int vowels(string s,int i)
{
if(i==s.size())
return 0;
char ch=s[i];
if(ch>='a'&&ch<='z')
ch=ch-32;
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
return 1+vowels(s,i+1);
else
return vowels(s,i+1);
}
int sum(int a[],int i,int n)
{
if(i>n-1)
return 0;
if(i==n-1)
return a[i];
return a[i]+sum(a,i+1,n);
}
bool palin(string s,int i,int n)
{
if(i==n-1)
return s[i]==s[0];
if(s[i]==s[n-1-i])
return palin(s,i+1,n);
return false;
}
int main()
{
string s;
int i,n;
cout<<"Enter string: ";
cin>>s;
cout<<"No of vowels in string is: "<<vowels(s,0)<<endl;
cout<<"Enter size of array: ";
cin>>n;
int a[n];
cout<<"Enter elements of array: ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Sum of array elements is: "<<sum(a,0,n)<<endl;
cout<<"Enter string to check for palindrome: ";
cin>>s;
n=s.size();
bool k=palin(s,0,n);
cout<<"Given string is palindrome:(True/False):- ";
if(k==1)
cout<<"True";
else
cout<<"False";
}

//please upvote.

Add a comment
Know the answer?
Add Answer to:
Write a recursive function, vowels, that return the number Of vowels in a string. Also, write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT