1. Engineering
  2. Computer Science
  3. persistent numbers the multiplicative persistence of a number is defined...

Question: persistent numbers the multiplicative persistence of a number is defined...

Question details

Persistent Numbers The multiplicative persistence of a number is defined by Neil Sloane (Neil J.A. Sloane in The Persistence of a Number published in Journal of Recreational Mathe matics 6, 1973, pp. 97-98. 1973) as the number of steps to reach a single-digit number when repeatedly multiplying the digits. For example 79378 16848 - 32-> 6 That is, the persistence of 679 is 5, Likewise, the persistence of 10-> 1 As one can imagine, the persistence of a single digit number is 0. As of now, it is known that there are numbers with the persistence of 1 1 (such as 2777 7778 88888 99) but it is not known whether here are numbers with由c pestcncc of 12. However, it is known that if such number do exist, the smallest of them would have more than 3000 digits in it. Some fun facts about persistence: The smallest number of persistence I The smaแest number of persistence 2 The smallest number of persistence 3 The smallest number of persistence4 The smallest number of persistence 5 The smallest number of persistence 6 is is is is is is 1o 25 39 77 679 6788 * The smallest number of persistence 7 is 68889 The smallest number of persistence &is 2677889 The smallest number of persistence 9 is 26888999 The smallest number of persistence 10 is 3778888999 You have been given a list of 125 9-digit numbers in an ASCII text fik such that each number is on a separate line. There are two parts of this homework assignment. PARTI 1 In this part, you will be writing another simple C program such that the prog㎜ will take name ofthe input file as command line argument name of the input file text file. If there is no argument,盧should wnte a usage message (indicating how to use this program) and terminate. Otherwise, it should recover the argument and from the provided fik, read the list of numbers. 2. Now sort the list within the program in ascending order using any sorting algorithm that you may know or have studied in the past. No external sorting or call to any sorting utility is allowed Calculate persistence of each of the number in the sorted list Find the number with the smallest and the largest persistence values and print both the numbers and their corresponding 3. persistence values. Calculate the CPU time it takes to de the entire set of steps 1-4 and print the CPU time 5. PART II 1. In this part of the homework assignment, you will be writing another simple C program that creates three child processes, parent I. The main ) will access the command line argument-name of a text file. If there is no argument, it should write a usage message (indicating how to use this program, and ermute Otherwise, should recover the aญument. COMP3300 Page I
media%2F1c0%2F1c09aa10-73fc-4c23-8416-97
Your homework assignment is due on the date mentioned above before the start of class time ie. 10.00 AM). As stated in course outline, late submission is not allowed/ accepted. Late submission marking provided by the Blackboard site will be used to detemine late submission. A Sample program to see how fork and pipe system calls work pipe.c PROTOTYPE: int pipe(int fd[2) RETURNS: 0 on success -1 on error could be because of - no file descriptors available system file table is full -fd array is not valid NOTESd O] is set for reading,fd) is set for writing #include #include #include <stdio.h> <unistd.h> <sys/types.h> int main(void) nt al2),nbytes pid t childpid char stringHello, world!n char readbuffer [80] f (1pipe (Ed) fprintf (stderr, pipe :Failed to create pipeln- exit (1) if you get warning, comment it out/ if((childpid fork()) -1) ** fprintf (stderr, fork: Failed to create child processin) exit(1) /if you get warning, comment it out if (childpid-0) close (fdIO]) /* Child proce ss closes up input side of pipe write (fd(1), string, strlen(string)) exit (0) Sendstringthrough the output side of pipe if you get warning,comment it out 7 else close (fd(1) /Parent process closes up output side of pipe /Read in a string from the pipe/ nbytes- read (fdi0. readbuf fer, sizeof (readbuffer)) fprintf (stderr, Received string: %s, readbuffer); return (O)
A Sample program to see how to find execution (CPO) time for execution in C exec time.c inelude # include #include <stdio.h> <t ime. h> <unistd.h> // for clock t, clock) // for sleepl) int main(void) double time spent -0.0 clock t beginclock O sleep (20) clock tend clockO // calculate elapsed time by finding difference (end -begin) and // to store execution time of code // do some stuff here // divide by CLOCKS PER SEC to convert to seconds t ime_ spent(double) (end begin) CLOCKS PER SEC printf rime elpased is i seconds. time spent) return 0
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution