Write a function that accepts a string as its only input. Print the string in re
ID: 3710014 • Letter: W
Question
Write a function that accepts a string as its only input. Print the string in reverse order without using any built-in reversal function.
rev(“hello”) > > > “olleh”
Write a function that accepts an integer parameter. Print out that integer as many times as its own value.
printX(5) > > > 55555
printX(3) > > > 333
printX(0) > > >
Do the same but with a float value. What trouble will you run into?
Write a function that accepts a String of size one and an integer. Have your function print the following patterns based on some inputs.
exer4(“d”, 5) --> d5d5d5d5d5
exer4(“a”,4) --> a4a4a4a4
exer4(“g”,0) -->
Explanation / Answer
#include <iostream>
using namespace std;
void rev(string s){
for(int i=s.length()-1;i>=0;i--){
cout<<s[i];
}
cout<<endl;
}
void printX(int n) {
for(int i=0;i<n;i++) {
cout<<n;
}
cout<<endl;
}
void exer4(string s, int n) {
for(int i=0;i<n;i++) {
cout<<s<<n;
}
cout<<endl;
}
int main()
{
rev("hello");
printX(5);
exer4("d", 5) ;
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.