Question
6. Complete the following codes in C code. a) Write a C program named x.c . Your program must read the standard input and write
6. Complete the following codes in C code.
a) Write a C program named x.c. Your program must read the standard input and write to the standard output. It must copy the input line to the output exactly as they are, and at the very end, just before the newline character, it must print a colon (:) and the line length. For example, if the input file looks as follows:
This is the first line.
No line above.
one more.
The output must be:
This is the first line.:23
:0
No line above.:14
one more.:9
You can assume that the input always ends with a newline character.
i) Functionality: Your program must satisfy the program requirements as specified.
ii) Implementation: The program must be implemented in the following way, and it will be marked by a marker. The program must use the getchar and putchar functions to copy input characters to the output. You should not use arrays to save characters. Instead, your program should read character by character and print them out as soon as they are read, and count them as well. Once the program reads the newline character ( ), it will print a colon (:) and the number of characters. You should use the printf function to print it.
b) Write a C program named y.c. Your program must read the standard input and write to the standard output. The program will read sequences of floating point numbers and for each 2 sequence print the average and median of the sequence. Each sequence is preceded with the number of elements in the sequence. So, the program will read first the number of elements of the sequence, then all elements of the sequence, print the average and median values, and repeat this process. The program will end the first time it reads a zero or negative number as the length of the sequence. The numbers are separated by whitespace. Remember that for the median you need to sort the array, and if the array has an odd number of elements the median is the element exactly in the middle; otherwise, if the array has an even number of elements, then the median is average of the two middle elements. The output numbers must be rounded to three decimals, and must follow the format below:
4
1 4 3.0
1
3
7.0 -1.0 5 0
the output must be:
Avg: 2.250 Med: 2.000
Avg: 3.667 Med: 5.000
i) Functionality: To satisfy this requirement, your program must satisfy the program requirements as specified.
ii) Implementation: The program must be implemented in the following way, and it will be marked by a marker. To calculate the median value, you should read numbers of a sequence in an array and sort them. You should declare the array after reading the sequence length, or you can assume that the array is at most 100 elements long and just declare an array of 100 elements. You must sort the array using the MergeSort algorithm. For this you must declare two functions that should be named merge_sort and merge or you can use similar names. It is allowed to copy the MergeSort algorithm.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started