Example 1: The function srnd(a) rounds sqrt(a) to the nearest integer. #include #include using namespace std; // function definition for srnd int srnd(double a) { int rvalue; double b = sqrt(a); if ((b-floor(b)) >= 0.5) rvalue = ceil(b); else rvalue = floor(b); return rvalue; } int main() { double x; cout << "Input a positive real number \n"; cin >> x; cout <<"The sqrt (rounded to nearest integer) is "<< srnd(x) <<"\n"; return 0; } Example 2 : The function strlt(str1,str2) returns 1 if str1 is smaller than str2 (in the dictionary ordering) and 0 otherwise. #include #include using namespace std; int strlt(char str1[], char str2[]) { int c=0; while (str1[c] == str2[c]) c++; if (str1[c] < str2[c]) return 1; else return 0; } int main() { char str1[40], str2[40]; cout << "Enter the two words \n"; cin >> str1 >> str2; // Only works with character arrays if (strlt(str1, str2)) cout << str1 << " " << str2 << "\n"; else cout << str2 << " " << str1 << "\n"; return 0; }