getMax function: int getMax ( int *list, int n ) { int i, maxValueIndex, maxValu
ID: 3777872 • Letter: G
Question
getMax function:
int getMax ( int *list, int n )
{
int i, maxValueIndex, maxValue;
if ( n == 0 )
return -1;
maxValueIndex = 0;
maxValue = list[0];
for ( i=1; i < n; i++ ) {
if ( maxValue < list[i] ) {
maxValue = list[i];
maxValueIndex = i;
}
}
return maxValueIndex;
}
Explanation / Answer
#include <iostream>
#include <cstring>
using namespace std;
const int MAXIMUM_LENGTH = 100;
int main()
{
char first_string[MAXIMUM_LENGTH];
char second_string[MAXIMUM_LENGTH];
cout << "Enter first string: ";
cin.getline(first_string,MAXIMUM_LENGTH);
cout << "Enter second string: ";
cin.getline(second_string,MAXIMUM_LENGTH);
cout << "Before copying the strings were ";
if (strcmp(first_string,second_string))
cout << "not ";
cout << "the same. ";
strcpy(first_string,second_string);
cout << "After copying the strings were ";
if (strcmp(first_string,second_string))
cout << "not ";
cout << "the same. ";
strcat(first_string,second_string);
cout << "After concatenating, the first string is: ";
cout << first_string;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.