Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSE 1502 Spring 2005 Project 1: Finding Prime Numbers with C++, Study Guides, Projects, Research of Computer Science

Project 1 for the cse 1502 spring 2005 introduction to software development with c++ course, which involves writing a c++ program to find and print all prime numbers between 2 and a given positive number p. Problem statement, inputs, outputs, validations, test values, hints, and acknowledgments.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/01/2009

koofers-user-v9c-1
koofers-user-v9c-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

Related documents


Partial preview of the text

Download CSE 1502 Spring 2005 Project 1: Finding Prime Numbers with C++ and more Study Guides, Projects, Research Computer Science in PDF only on Docsity! CSE 1502 Spring 2005 Introduction to Software Development with C++ Instructor: Venkatesh Ramamoorthy Project 1 Turn in by 31-March-2005 Problem Statement For a given positive number p, write a C++ program that finds and prints all of the prime numbers between 2 and p (both inclusive). A prime number is a number that can only be divided by one and itself (e.g. the numbers 2, 3, 5, 7, 11, 13, 17, . . .). Note that 0 and 1 are not in the example list; this is because 0 and 1 are neither prime nor composite. Note also, that 2 is the only even prime number. Inputs The positive number p up to which the first several prime numbers are required to be displayed. Outputs The list of prime numbers 2, 3, 5, 7, . . . p, if p is prime. If p is not prime, p is excluded from this list. Validations Based upon the discussion in the problem statement, what validations can you think of, that need to be applied on the input p? Test values The list of prime numbers up to, and including, 107, are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107 File Name Ensure that the file-name in which you are turning in this program, is called primes.cpp Project Name The project name in which this Project is turned in is project01. Acknowledgments This assignment originally appeared in a specialized form in “Absolute C++” by Walter Savich, (Instructor’s compli- mentary copy), Pearson Education, Inc., Addison-Wesley, Problem 4, Page 93. Hints One way to solve this problem is to use a doubly-nested loop. The outer loop runs with a counter value from 2 to p, while the inner loop checks to see whether the counter value for the outer loop is prime. That leaves us with the following question: How do we “check” to see if a number is prime or not? One way to decide whether a number p is prime is to loop from 2 to (p − 1); if any of these numbers evenly divides p, then p cannot be prime. If none of the values from 2 to (p − 1) evenly divide p, then p must be prime. (Note that there are several easy ways to make this algorithm more efficient).
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved