Files
-
Assume an input file of the following format is provided:
N i_1 i_2 ... i_NNis the number of integers below in the file.i_1…i_Nare the integers.Write a program that reads the integers from the file and writes them in a new file. The output file must contain the number of integers first, then odd integers in the same order as in the input file, and then even integers in the same order as in the output file.
Example:
Input:
5 4 3 5 2 9Output:
5 3 5 9 4 2 -
Implement a program that creates a file that contains all prime numbers up to a given
n.Consider implementing the sieve of Eratosthenes.
Example. For
n = 102 3 5 7 11 13 17 19 23 29 31 -
Assume the number of rows
nand the number of columnsmare given.Write a program that writes a rectangular grid with
nrows andmcolumns to a file.Example. For
n = 4andm = 5.┌──┬──┬──┬──┬──┐ │ │ │ │ │ │ ├──┼──┼──┼──┼──┤ │ │ │ │ │ │ ├──┼──┼──┼──┼──┤ │ │ │ │ │ │ ├──┼──┼──┼──┼──┤ │ │ │ │ │ │ └──┴──┴──┴──┴──┘ -
Write a program that reads a text from a file and prints the number of words in the text. The words are separated by following characters: space (‘ ‘) or new line (‘\n’) or tab (‘\t’) or a combination of these.
Example. For the text
Hello! I love programming! Twinkle Twinkle Little starthe output is
8.