There is another error besides the already mentioned one of incrementing
i
instead of
j
in the inner loop:
You are accessing the characters of the strings up to the index
n
. That won't work if
n
is greater then the length of the strings.
Both errors result in out of bound accesses (accessing characters out of the memory used by the strings) which result in undefined behaviour or - in the worst case as here - segmentation faults.
Instead of letting the user enter the value for
n
, use the length of the entered string:
int n = s.length();
Use that to search for the smallest letter as suggested in solution 1.