There are 3 country names, find the first alphabetical string in the country
The code is as follows:
#include <iostream> #include <string>using namespace Std;int main () { void smallest_string (char str[] 30],int i);//function declaration int i; Char country_name[3][30];//defines a two-dimensional character array, which has a two-dimensional character array as 3 one-dimensional character arrays, each of which has 30 elements for (i=0;i<3;i++) cin>> Country_name[i]; Smallest_string (country_name,3); Call the Smallest_name function to pass the character array name to the parameter return 0;} void Smallest_string (char str[][30],int n) { int i; Char string[30]; strcpy (String,str[0]); Daleitai algorithm for (i=0;i<n;i++) if (strcmp (str[i],string) <0) strcpy (String,str[i]); cout<<endl<< "The smallest string is:" <<string<<endl; }
Note: You can compare characters in any situation whenever you change some of the parameters of this function.
Copyright NOTICE: This article is my original article, we can reprint Oh!!
Array of strings