Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ array please make the output same as the example Write a function printNthCh

ID: 3587901 • Letter: C

Question

c++ array please make the output same as the example

Write a function printNthCharacter that prints the nth character from every string in an array of strings It should take as input an array of strings words an integer size for the size of the array an integer n for the position of the character to be printed from each string It should print the nth characters of the strings in the array Example: For this input ("hey you", "echo", "loyal", We expect this output: hello "little", "orange"), n = 0 Since these are the nth(0th) characters of the strings in the array "hey you". "echo", "Joyal", "ittle". "orange" Start by writing the function to print out all the strings in their entirety. (hey youecholoyallittleorange). Then modify it so that only the nth character of each string is printed (hello)

Explanation / Answer

#include <iostream>

using namespace std;
void printNthCharacter(string s[], int size, int n) {
for(int i=0;i<size;i++) {
cout<<s[i][n];
}
cout<<endl;
}
int main()
{
string s[5] = {"hey you", "echo", "loyal", "little", "orange"};
int n = 0;
int size = 5;
printNthCharacter(s, size, n);
return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote