This program declares an array of Chan of size max Size, and prompts the user to
ID: 3808314 • Letter: T
Question
This program declares an array of Chan of size max Size, and prompts the user to type letters, either until the array is full or until the user types the character #. After next asking the user to input a letter, it outputs the input sequence with all occurrences of that letter deleted. The letters occurring in the output are in the same order as they were in the input, and the output has no gaps. The program works with a single array segment -- once this segment has been filled, the very same array segment is processed to remove all occurrences of the input letter, and all gaps which arise as a result of these removals. The processed array is printed. You cannot solve this problem by printing directly from the originally input array segment you must first transform the input array. Thus, if max Size is 10, and the user types abcbad#, and then selects b as the letter to remove, the program modifies the input array so that its contents are acad. and then prints these letters. If for this input the user selected z as the letter to remove, the processed array segment is the same as the input array segment, and the original segment is output. If the user types precisely max Size letters - say abedeabede when max Size is 10 - then # is not needed to terminate the input. After each run. the user is asked whether a repeat computation is wanted.Explanation / Answer
#include<stdio.h>
#define maxSize 10//defining maxSize as 10
int main()
{
int i,j,k=0,size,check;
int arr1[maxSize];//for taking input from user
int arr2[maxSize];//to store after removing duplicates
printf("Enter letters.... [to stop enter #] ");
for(i=0;i<maxSize;i++)
{
scanf("%c",&arr1[i]);
if(arr1[i]=='#')//if # entered loop will break
break;
}
size=i;//array size after coming from the user
for(i=0;i<size-1;i++)
{
check=0;//its a flag to identify if there are any removal occured, if occured check will be positive number or else its just zero
for(j=i+1;j<size-1;j++)
{
if(arr1[i]==arr1[j]&&arr1[i]!='0')//if any duplicate found, and it must be not zero
{
arr1[j]='0';//if found any duplicate, we make thats letter as 0
check++;//flag incremented
}
}
if(check==0&&arr1[i]!='0')//if any removal not occured then add that letter into arr2
arr2[k++]=arr1[i];
}
//printing after removing all duplicates
for(i=0;i<k;i++)
printf("%c",arr2[i]);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.