3 Pages

Programming Assignment #3

Course: EE 312, Spring 2008
School: University of Texas
Rating:
 
 
 
 
 

Word Count: 1148

Document Preview

3: Assignment Fun with Primes Assigned: Design Due: Program Due: Total Value: EE312 The University of Texas at Austin Spring 2008 Tuesday, February 12th Tuesday, February 19, at the beginning of class Tuesday, February 26, before midnight 20 points total (see Deliverables below for details). Purpose Learning how to design your program before coding Learning how to write and use functions in your programs...

Register Now

Unformatted Document Excerpt

Coursehero >> Texas >> University of Texas >> EE 312

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
3: Assignment Fun with Primes Assigned: Design Due: Program Due: Total Value: EE312 The University of Texas at Austin Spring 2008 Tuesday, February 12th Tuesday, February 19, at the beginning of class Tuesday, February 26, before midnight 20 points total (see Deliverables below for details). Purpose Learning how to design your program before coding Learning how to write and use functions in your programs Learning about array manipulation Background The Sieve of Eratosthenes is a simple, ancient algorithm for finding all the prime numbers up to a specified integer. It was created by Eratosthenes (in 276 BC - 194 BC), a Greek mathematician, geographer and astronomer. For more information see Wikipedia http://en.wikipedia.org/wiki/Eratosthenes Deliverables There are both design (4 points) and code (16 points) deliverables for this assignment. The design portion requires that you produce these two items on paper: 1. Functional Block diagram identifying the main program and all subfunctions, showing who calls whom, and what data is passed to and from different blocks (2 points) 2. Flow chart or pseudocode of your program's main logic 1 page should be sufficient detail (2 points) Turn these in at the beginning of your Tuesday, February 19th lecture period with your name and unique section number written clearly on them. It would be a good idea (not required) to have your design reviewed by a TA in the lab before starting to write any code. The code deliverable will be submitted through the Blackboard assignment manager as usual. It will be a file named primes.c that contains all the source code and comments that meet the requirements for this assignment. Your code must also conform to the C coding standards for this course (as posted on the Blackboard for your section). Assignment Description Develop a program using the sieve algorithm below to display all n prime numbers starting from 2, where n is a value specified by the user. Prime numbers are represented in integer format. The user will be asked to input a number n. The program will then display n primes starting from 2. In your program, prime numbers are to be stored in the short int type. If the size of the largest prime number to be displayed exceeds the capacity of the system, then the program should give the longest series of primes that can be displayed and state that a further list of prime numbers cannot be generated. After displaying the complete list of n prime numbers, the program will find and output those prime numbers in the range which have additional Page 1 of 3 Assignment 3: Fun with Primes EE312 The University of Texas at Austin Spring 2008 characteristics as defined below. Your program should allow the user to do the above for additional input values, by prompting the user and accepting a `Y' or `N' character to determine whether to repeat or not. Input requirements The user is asked to input a number n (an integer) which represents the number of prime numbers to be displayed. The program should determine whether the input value is valid (based on the value ranges of integer types on the particular machine). In this case, the input value is invalid if the nth prime number is too large for the system. Your program does not have to disallow an invalid input; instead, it should handle the invalid integer input as discussed in the assignment description. The only other valid (non-integer) inputs are `Y' and `N', which the inputs user when queried after the programs' output. Any other non-integer input should cause the program to reprompt the user for the correct input. Output requirements Display the final set of prime numbers in an 8 column, table format. The prime numbers must be in ascending order with the lowest prime in row 1, column 1. The numbers must read in descending order from top to bottom and then left to right. The output table must have exactly 8 columns unless there are fewer than 9 values to display, in which case only a single row is necessary. The numbers must each fit into a field of size 10, right justified. For example, this displays the first 20 numbers in the correct format. Note that these are NOT prime numbers but simply the location in the output table each prime would take: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Sieve algorithm A list is a collection of similar elements in which each element has a specified position (e.g. sequence number) in the list. A list can be implemented in C as a 1-D array. Steps in determining the primes: 1. Write a list of numbers from 2 to the largest number you want to test for primacy. Call this List A. 2. Write the number 2, the first prime number, into another list for primes found. Call this List B. 3. Strike off 2 and all multiples of 2 from List A. 4. The first remaining number in List A is a prime number. Write this number into List B. 5. Strike off this number and all multiples of this number from List A. Page 2 of 3 Assignment 3: Fun with Primes EE312 The University of Texas at Austin Spring 2008 6. Repeat steps 4 through 6 until no more numbers are left in List A. Actually, for efficiency, the crossing-off of multiples can be finished at the midpoint of the range or at the square root of the largest number. 7. List B now contains all the prime numbers in that range. List A can be discarded. Processing of Primes for Additional Characteristics After the list of primes are found and output, the list of primes should be processed again to find and report those that have the following additional characteristics. Find and report the list of primes for which two consecutive prime numbers have a difference of four. For example 11 7 = 4 In other words find Pn+1,Pn such that Pn+1 Pn= 4 Output the list of the pairs of numbers whose difference is 4, with each pair on a separate line. The above example would output something like: The pair of primes 7,11 has a difference of 4 Next, find all those primes in the list (B) which are CPSPs of order-3. A Consecutive-Prime Sum Prime (CPSP) of order-3 is a prime number that is the sum of three consecutive prime numbers. For example, when added together, 5, 7, and 11 (all primes in sequence) equal 23 (another prime number). In other words, find those values of Pn, Pn+1, Pn+2, Pk such that: Pn + Pn+1+ Pn+2 = Pk (Pk does not have to be the next prime in sequence) Output the four primes in the format Pn+ Pn+1 + Pn+2 = Pk, with each group of four on a separate line. For example, the above would output something like: 5 + 7 + 11 = 23 (which is a CPSP of order-3) Design requirements You must implement the solution using arrays. You may use as many functions as you find necessary to improve modularity and understandability of your program. You must include a minimum of two functions besides the main function. These should be written with a view of reusing them in a future ee312 course assignment. Page 3 of 3
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Texas - EE - 312
Assignment 1: Introduction to the LRC Lab, Visual Studio, and CEE312 The University of Texas at Austin Spring 2008 Assigned: Due: Value: Tuesday, January 15, 2008 Thursday, January 24, 2008, before midnight 20 points (for successfully submitting a
University of Texas - EE - 312
Announcements Assignment 4 D i Designs due RIGHT NOW d RIGHT NOW Due Thursday before midnight Topics for today RecursionRecursion Recursion in C is simply when a function calls itself It is also an important problem solving approach A fun
University of Texas - EE - 312
Announcements Assignment 3 D Due next Tuesday by midnight t T d b id i ht Assignment 4 Out next Tuesday Out next Tuesday I'm out of town all next week Professor Krasner will be in next week to continue lectures Professor Krasner will be in n
University of Texas - EE - 312
Weekly ScheduleM 9:00 Nikhil Nikhil 10:00 Shadi, Nikhil Shadi, Nikhil, Sunil 11:00 Shadi, Nikhil, Sunil Shadi, Nikhil, Sunil 12:00 Shadi, Sunil Shadi 13:00 Mahesh Mahesh 14:00 Mahesh Shadi, Mahesh 15:00 Shadi, Mahesh Shadi, Mahesh 16:00 Shadi, Mahes
University of Texas - EE - 312
Announcements Assignment 2 Offi Office Hours today d Topics for today Type conversions and casting Typedef and sizeof arrays 1D arrays 1DUsual Arithmetic Conversions in Expressions Promotions, e.g: A + B Promotions e g: A + BIn mixed type
University of Texas - EE - 312
Announcements Assignment 2 due today! Exam 1 next Thursday 50 minute exam (9:30 10:20) Topics for today Functions Scope of variables1Functions in a Nutshell A named collection of statements Somewhat like mathematical functions: y = f(
University of Texas - EE - 312
Announcements Assignment 2 Topics for today i f d Partially filled arrays Array algorithms Array algorithms Multidimensional arraysPartially Filled Array Arrays cannot grow after they have been allocated p ( ) y You can allocate more space
University of Texas - EE - 312
Announcements Blackboard Discussion Blackboard Discussion Avoid emailing your TAs with questions about assignments/lectures Course Communication Groups Opt out by today 5pm Optout by today 5pm For today: Finish floating point numbers Format
University of Texas - EE - 312
Announcements Assignment 3 out today Assignment 3 and 4 logisitics Exam 1 Thursday 55 minute exam (9:30 10:25) Program Development Measurement g p SLOC, person hours, logic defects Topics for today Topics for today Scope of variables Ex
University of Texas - EE - 312
Announcements Assignment 3 Exam 1 Graded Back in recitations on Friday Statistics on Thursday (hopefully) Read Chapters 11,12, 13 and 22 Topics for today Matrices Random numbers Strings (time permitting)Review: 2D Arrays Used for table
University of Texas - EE - 312
Announcements Assignment 2 posted today Assignment 2 posted today Quizzes C Coding Style C C di S l For today: Finish looping control statements (Chap. 6) More on types (Chap. 7)For loop The for statement has the formfor ( expression1 ; exp
University of Texas - EE - 312
E E 312 Notes 2.5Arrays Matrix Int variable [r][c] Int my2Darray [3,3] o That means evaluate 3 for 3 Use for statement and nested loops Allows you to make a change in the rows and columns Scan ( %f, &energy[][]); 2d arrays Not easier for us to do
University of Texas - EE - 312
E E 312 Notes February 7, 2008--A named collection of statements o Somewhat like mathematical functions o Arguments are not required Does not need to return a value Functions are like "mini-programs" called by name Top line: declarations Libra
University of Texas - EE - 312
E E 312 Notes February 12, 2008Know Source Lines of Codes Know how many hours you spent on your assignment o Need to do this for Assignment #2 Global Variables o Also called external variables o Are declared outside of your main function o Should
University of Texas - EE - 312
Announcements Assignment 1 due tonight Assignment 1 due tonight Blackboard assignment manager More on Blackboard discussion board More on Blackboard discussion board getchar() For today: Introduction to algorithm design using flowcharts or ps
University of Texas - EE - 312
EE 312 Notes--------Malloc = sets a memory block for the size of bytes you need o Used as a pointer o Ex: p = malloc(sizeof(int); o Will return null if cannot find size o Make sure to check for null Calloc= allocates space for an ar
University of Texas - EE - 312
EE312 Lecture 2 Announcements Topics for today will answer the questions: Survey Results What is the C programming language ? What is C syntax ? What is C s nta ? Assignment statement Numerical expressions Numerical expressions Number stora
University of Texas - EE - 312
Weekly ScheduleM 9:00 Nikhil Nikhil 10:00 Shadi, Nikhil Shadi, Nikhil, Sunil 11:00 Shadi, Nikhil, Sunil Shadi, Nikhil, Sunil 12:00 Shadi, Sunil Shadi 13:00 Mahesh Mahesh 14:00 Mahesh Shadi, Mahesh 15:00 Shadi, Mahesh Shadi, Mahesh 16:00 Shadi, Mahes
University of Texas - EE - 312
16 Frequency Table Type Instruction count 0 3 1 1 2 3 3 2 4 4 5 0 6 3 7 0 8 0 9 0 5 Frequency Table Type Instruction count 0 0 1 1 2 1 3 0 4 2 5 0 6 0 7 1 8 0 9 0 835 Frequency Table Type Instruction count 0 822 1 1 2 1 3 1 4 2 5 3 6 2 7 1 8 1 9 1 15
University of Texas - EE - 312
EE312 Introduction to Programming I d i P iSpring 2008 Christine Julien Christine Julien Assistant Professor c.julien@mail.utexas.edu Office: ACES 5.140 Offi ACES 5 140 Office Hours: TTh: 1112:30Introductions The Teaching Team Instructor Chris
University of Texas - PHY - 303K
homework 05 FONTENOT, BRIAN Due: Feb 18 2008, 4:00 am Question 1, chap 5, sect 5. part 1 of 2 10 points A child holds a sled on a frictionless, snowcovered hill, inclined at an angle of 26 . F87 N 01Question 4, chap 5, sect 5. part 2 of 2 10 p
University of Texas - EE - 312
E E 312 Notes 1.27For Loops For (expression 1; expression 2; expression 3) statement Ex: for (i=10; I > 0; i-) o Printf("T Minus %d and counting\n", i) - I is at 10, check if I is greater than zero, then decrement I and go back and check to see if
University of Texas - PHY - 303K
oldmidterm 01 FONTENOT, BRIAN Due: Feb 14 2008, 3:00 pm Question 1, chap 1, sect 5. part 1 of 1 10 points A newly discovered Jupiter-like planet has an average radius 10.6 times that of the Earth and a mass 313 times that of the Earth. Calculate th
University of Texas - PHY - 303K
midterm 01 FONTENOT, BRIAN Due: Feb 13 2008, 11:00 pm1Mechanics - Basic Physical ConceptsMath: Circle: 2 r, r2 ; Sphere: 4 r2 , (4/3) r3 b2 Quadratic Eq.: a x2 + b x + c = 0, x = -b 2 a-4 a cCartesian and polar coordinates: y x = r cos ,
University of Texas - EE - 312
E E 312 Discussion Notes How to Read arrays: /* Int couter, coutner2 For (coutner=0, array[coutner] < nextinput; coutner+); For (counter 2= arraysize; counter2>count; coutner2 -) { Array[count2]=array[count 2-1]; Arrayszie+ Scanf("); */
University of Texas - PHY - 303K
homework 04 FONTENOT, BRIAN Due: Feb 11 2008, 4:00 am Question 1, chap 4, sect 5. part 1 of 3 10 points An athlete swings a 6.72 kg ball horizontally on the end of a rope. The ball moves in a circle of radius 0.995 m at an angular speed of 0.787 re
University of Texas - PHY - 303K
homework 04 FONTENOT, BRIAN Due: Feb 11 2008, 4:00 am Question 1, chap 4, sect 5. part 1 of 3 10 points An athlete swings a 6.72 kg ball horizontally on the end of a rope. The ball moves in a circle of radius 0.995 m at an angular speed of 0.787 re
University of Texas - PHY - 303K
homework 05 FONTENOT, BRIAN Due: Feb 18 2008, 4:00 am Question 1, chap 5, sect 5. part 1 of 2 10 points A child holds a sled on a frictionless, snowcovered hill, inclined at an angle of 26 . F87 N1= T = W sin = (87 N) sin 26 = 38.1383 N .Qu
University of Texas - PHY - 303K
homework 02 FONTENOT, BRIAN Due: Jan 28 2008, 4:00 am Question 1, chap 2, sect 5. part 1 of 3 10 points In deep space (no gravity), the bolt (arrow) of a crossbow accelerates at 129 m/s2 and attains a speed of 125 m/s when it leaves the bow. For ho
University of Texas - PHY - 303K
homework 03 FONTENOT, BRIAN Due: Feb 4 2008, 4:00 am Question 1, chap 3, sect 4. part 1 of 3 10 points Consider the two vectors M = (a, b) = a^+ i b ^ and N = (c, d) = c^ + d ^, where a = 4, i b = 4, c = 3, and d = -3. a and c represent the x-dis
University of Texas - PHY - 303K
homework 03 FONTENOT, BRIAN Due: Feb 4 2008, 4:00 am and Question 1, chap 3, sect 4. part 1 of 3 10 points Consider the two vectors M = (a, b) = a^+ i b ^ and N = (c, d) = c^ + d ^, where a = 4, i b = 4, c = 3, and d = -3. a and c represent the x
University of Texas - PHY - 303K
homework 07 FONTENOT, BRIAN Due: Mar 3 2008, 4:00 am Question 1, chap 8, sect 1. part 1 of 3 10 points A 3 kg block collides with a massless spring of spring constant 94 N/m attached to a wall. The speed of the block was observed to be 1.3 m/s at t
University of Texas - EE - 312
E E 312 NotesArithmetic Conversions With Floats o o Float + Double = Double Double + Int = DoubleNot With Floats o Int + int = int o Int < unsigned int < long int o Never combine unsigned ints and regular ints in expressions The value on the righ
University of Texas - EE - 312
EE 312 Notes Recursion using the stack Parameters are stored in the stack Stacks are LIFO Pushing = Adding an Item Popping = Removing an Item System Support Maintains an activation record Activation Record (Stack Frame) looks like the following o Inc
University of Texas - EE - 312
EE 312 NotesExam 2: Chapters 9.6 11-13; 15-17; 22. File Inclusion Want to include own file. Use #include "filename" Looks in local directories first Only One source file must contain a definition of main Create header files to include just your hea
University of Texas - PHY - 303K
homework 06 FONTENOT, BRIAN Due: Feb 25 2008, 4:00 am Question 1, chap 7, sect 1. part 1 of 3 10 points Assume you are on a planet similar to Earth where the acceleration of gravity g 10 m/s2 . A plane 50 m in length is inclined at an angle of 16.
University of Texas - PHY - 303K
midterm 01 FONTENOT, BRIAN Due: Feb 13 2008, 11:00 pm1Mechanics - Basic Physical ConceptsMath: Circle: 2 r, r2 ; Sphere: 4 r2 , (4/3) r3 b2 Quadratic Eq.: a x2 + b x + c = 0, x = -b 2 a-4 a cCartesian and polar coordinates: y x = r cos ,
University of Texas - EE - 312
EE312 C Coding Standards Spring 2008Writing code that is easy for others (or you later) to read is an important part of programming. Style entails a program's readability and logic structuring. Style is almost as important as correctness in program
University of Texas - EE - 312
E E 312 Discussion 1.18.2008 Most general computer Consist of a microprocessor o o o Intel x86 Takes instructions Computes a resultProgrammer o o o o o Job is to write instructions to build jobs Use programming language Our language is C Something
University of Texas - EE - 312
Dicussion Session EE 312 1/25/08Printf (" %4d", 86); Printf("%06d", 86); Printf("%4d", 10405); shows*/ Printf("%12.5e, 30.253); Control Statements: If(i>2) J = 100; Else J =-100; Can set Multiple Parameters= = = =|_|_86| |000086| |10405| /* On
University of Texas - EE - 312
C PROGRAMMING A Modern ApproachAnswers to Even-Numbered ExercisesSusan A. Cole K. N. KingW W Norton & Company New York LondonCopyright 1996 W. W. Norton & Company, Inc. All rights reserved. W. W. Norton & Company, Inc. 500 Fifth Avenue, Ne
University of Texas - EE - 312
EE 312 Programming Project #3 Flow Chart Brian Fontenot (BLF339) 15670 F: 11-12
University of Texas - EE - 312
EE 312 Programming Project #3 Flow Chart Brian Fontenot (BLF339) 15670 F: 11-12Start programdeclare variablesdeclare arrayIntialize arrayIntialize variablesprompt user informationscan for user inputread user inputsort out prime num
University of Texas - EE - 312
10 299 492 495 399 492 495 399 283 279 689 078 100 000 000 000 456 789 234 453 125 175 183 256 012 100 000 212 415 521 721 532 439 543 631 339 923 029 873 674 027 023 610 621 632 643 654 665 676 687698 609 201 805 229 429 100 100 456 789 234 453 12
University of Texas - EE - 312
EE312 Introduction to Programming I d i P iSpring 2008 Christine Julien Christine Julien Assistant Professor c.julien@mail.utexas.edu Office: ACES 5.140 Offi ACES 5 140 Office Hours: TTh: 1112:30Introductions The Teaching Team Instructor Chris
University of Texas - EE - 312
EE312 Lecture 2 Announcements Topics for today will answer the questions: Survey Results What is the C programming language ? What is C syntax ? What is C s nta ? Assignment statement Numerical expressions Numerical expressions Number stora
University of Texas - EE - 312
Micro architecture, logic circuits, and device technology -1st layer hardware vs. software Machine assembly language instruction set machine code High level programming language - c programming Not finished Need the designModels, design, and abstr
University of Texas - EE - 312
Notes 1.17 The History of C Was called NB o BCPL Orignated from the UNIX System By Denins Ritchie in Bell Labs Between 1969 and 1973 Became popular in the 1980s Original C o Called K&R C By Kernighan and Ritchie o ANSI C ANSI Standard X3.159-1989
University of Texas - EE - 312
Read Chapter 3, 7, 22 Know Chapter 2 for Quiz on FridayNotes 1.22 Floats Float single precision Double double precision Long double extreme precision Must contain decimal point or exponent By default stored as double-precision numbers F or f, L
University of Texas - EE - 312
EE 312 Notes January 24, 2008Selection o Deciding among alternative executive paths Boolean values stored in variables Tested by program Using If and Else Statements Nested and Cascaded If statements Using Switch Statements Conditional Operators
University of Texas - EE - 312
EE 312 Notes January 24, 2008Sequence Follow Sequence 1, 2, 3 Condition is True Do until false Iteration False loop back to beginSelection Condition is true go to end Condition is not true, then do functionSelection o Deciding among a
University of Texas - EE - 312
E E 312 Notes Argc = number of pointers Char *argv[] = each value that is pass into function Int main ( int argc, char *argv[]) Command line >myprog.c one two three Argc = 4 Argv[0] = "my prog.c" Argv[1]="one" Argv[2] = "two" Argv[3] = "three" File i
University of Texas - BIO - 311C
Chapter 7Membrane Structure and FunctionLecture OutlineOverview: Life at the Edge The plasma membrane separates the living cell from its nonliving surroundings. This thin barrier, 8 nm thick, controls traffic into and out of the cell. Like all
University of Texas - BIO - 311C
Chapter 13Meiosis and Sexual Life CyclesLecture OutlineOverview: Hereditary Similarity and Variation Living organisms are distinguished by their ability to reproduce their own kind. Offspring resemble their parents more than they do less closely
University of Texas - BIO - 311C
Chapter 14 Mendel and the Gene IdeaLecture OutlineOverview: Drawing from the Deck of Genes Every day we observe heritable variations (such as brown, green, or blue eyes) among individuals in a population. These traits are transmitted from parents t
University of Texas - BIO - 311C
Chapter 16Lecture OutlineThe Molecular Basis of InheritanceOverview: Life's Operating Instructions In April 1953, James Watson and Francis Crick shook the scientific world with an elegant double-helical model for the structure of deoxyribonuclei
University of Texas - BIO - 311C
Chapter 15The Chromosomal Basis of InheritanceLecture OutlineOverview: Locating Genes on Chromosomes Today we know that genes-Gregor Mendel's "hereditary factors"-are located on chromosomes. A century ago, the relationship of genes and chromosom
University of Texas - BIO - 311C
Chapter 17From Gene to ProteinLecture OutlineOverview: The Flow of Genetic Information The information content of DNA is in the form of specific sequences of nucleotides along the DNA strands. The DNA inherited by an organism leads to specific t
University of Texas - BIO - 311C
Chapter 18The Genetics of Viruses and BacteriaLecture OutlineOverview: Microbial Model Systems Viruses and bacteria are the simplest biological systems- microbial models in which scientists find life's fundamental molecular mechanisms in their m
University of Texas - BIO - 311C
Chapter 20DNA Technology and GenomicsLecture OutlineOverview: Understanding and Manipulating Genomes One of the great achievements of modern science has been the sequencing of the human genome, which was largely completed by 2003. Progress began
University of Texas - BIO - 311C
Chapter 19Eukaryotic GenomesLecture OutlineOverview: How Eukaryotic Genomes Work and Evolve Two features of eukaryotic genomes present a major information-processing challenge. First, the typical multicellular eukaryotic genome is much larger th