WRITE IN C 10.11 Write a program that reads characters and stores them in an arr
ID: 3712574 • Letter: W
Question
WRITE IN C
10.11 Write a program that reads characters and stores them in an array of 100 places with the restriction that no duplicated character is stored. If the user enters 'q' or the array is full, the insertion of characters should terminate. U.10.12 Write a program that reads a string of less than eight characters that represents a hexadecimal number (accepted characters: 0-9, a-f, A-F) and displays the corresponding decimal value. For example, if the user enters 1AF, the program should display 431. U.10.13 Suppose that each lowercase letter has a value as follows. The letters 'a' up to 'i correspond to units; 'a' has the value 1 and 'i' is 9. The letters 'j' up to 'r' correspond to tens; 'J ' has the value 10 and 'r' is 90. The rest correspond to hundreds; 's' has the value 100 and 'z' is 800. Write a program that continuously reads strings (less than 100 characters each) and dis- plays the strings with the largest and smallest value and those values as well, before it ends. For example, the value of cky is 723, while the value of A9m is 40, since the charac- ters 'A' and '9' don't have a value. If more than one string has the same largest or smallest value, the program should display the one entered last. If the user enters ***, the insertion of strings should terminate. U.10.14 Write a program that reads two strings of less than 100 characters and removes every occurrence of the second string inside the first one. After each removal, the remain ing part of the first string should be shifted to the left, a number of places equal to the characters of the second string. The program should display the first string, before it ends For example, if the first string is thisthat though and the second is th, the program should display isat ough.Explanation / Answer
Doing first one as per chegg policy
#include <stdio.h>
int main()
{
char arr[101];
int i = 0;
while(i < 100) {
char c;
printf("Enter char (q to quit): ");
scanf(" %c", &c);
if (c == 'q') {
break;
} else {
int j;
int matchFound = 0;
for(j = 0; j < i; j++) {
if(arr[j] == c) {
matchFound = 1;
break;
}
}
if (matchFound == 0) {
arr[i] = c;
i++;
}
}
}
arr[i] = '';
printf("Read char array is %s ", arr);
return 0;
}
sample run
Enter char (q to quit): 1
Enter char (q to quit): a
Enter char (q to quit): t
Enter char (q to quit): y
Enter char (q to quit): u
Enter char (q to quit): h
Enter char (q to quit): j
Enter char (q to quit): t
Enter char (q to quit): i
Enter char (q to quit): a
Enter char (q to quit): q
Read char array is 1atyuhji
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.