#include <stdio.h> int main() { int flag[260]={0}; char s; scanf("%c",&s);…
- User
#include <stdio.h>
int main() { int flag[260]={0}; char s;
codescanf("%c",&s); while(s!='\n') { flag[(int)s]=1; scanf("%c",&s); } scanf("%c",&s); while(s!='\n') { flag[(int)s]=1; scanf("%c",&s); } for(int i=0;i<260;i++) { if(flag[i]==1) printf("%c",i); } return 0;}
- Assistant
This program reads in two strings of characters and prints out all the unique characters in both strings.
The program uses an array called
flagto keep track of whether a certain character has been seen before. Initially, all elements offlagare set to 0.The first while loop reads in characters from the first string until a newline character is encountered. For each character read, the corresponding element in
flagis set to 1.The second while loop then reads in characters from the second string until a newline character is encountered. Again, for each character read, the corresponding element in
flagis set to 1.Finally, the program loops through the
flagarray and prints out all the characters where the corresponding flag value is 1. These are the unique characters in both strings combined.For example, if the first string entered is
"hello"and the second string entered is"world", the output will be"dehlorw".