Search Results

Search found 25401 results on 1017 pages for 'adobe partner program'.

Page 71/1017 | < Previous Page | 67 68 69 70 71 72 73 74 75 76 77 78  | Next Page >

  • Help with Java Program for Prime numbers

    - by Ben
    Hello everyone, I was wondering if you can help me with this program. I have been struggling with it for hours and have just trashed my code because the TA doesn't like how I executed it. I am completely hopeless and if anyone can help me out step by step, I would greatly appreciate it. In this project you will write a Java program that reads a positive integer n from standard input, then prints out the first n prime numbers. We say that an integer m is divisible by a non-zero integer d if there exists an integer k such that m = k d , i.e. if d divides evenly into m. Equivalently, m is divisible by d if the remainder of m upon (integer) division by d is zero. We would also express this by saying that d is a divisor of m. A positive integer p is called prime if its only positive divisors are 1 and p. The one exception to this rule is the number 1 itself, which is considered to be non-prime. A positive integer that is not prime is called composite. Euclid showed that there are infinitely many prime numbers. The prime and composite sequences begin as follows: Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, … Composites: 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, … There are many ways to test a number for primality, but perhaps the simplest is to simply do trial divisions. Begin by dividing m by 2, and if it divides evenly, then m is not prime. Otherwise, divide by 3, then 4, then 5, etc. If at any point m is found to be divisible by a number d in the range 2 d m-1, then halt, and conclude that m is composite. Otherwise, conclude that m is prime. A moment’s thought shows that one need not do any trial divisions by numbers d which are themselves composite. For instance, if a trial division by 2 fails (i.e. has non-zero remainder, so m is odd), then a trial division by 4, 6, or 8, or any even number, must also fail. Thus to test a number m for primality, one need only do trial divisions by prime numbers less than m. Furthermore, it is not necessary to go all the way up to m-1. One need only do trial divisions of m by primes p in the range 2 p m . To see this, suppose m 1 is composite. Then there exist positive integers a and b such that 1 < a < m, 1 < b < m, and m = ab . But if both a m and b m , then ab m, contradicting that m = ab . Hence one of a or b must be less than or equal to m . To implement this process in java you will write a function called isPrime() with the following signature: static boolean isPrime(int m, int[] P) This function will return true or false according to whether m is prime or composite. The array argument P will contain a sufficient number of primes to do the testing. Specifically, at the time isPrime() is called, array P must contain (at least) all primes p in the range 2 p m . For instance, to test m = 53 for primality, one must do successive trial divisions by 2, 3, 5, and 7. We go no further since 11 53 . Thus a precondition for the function call isPrime(53, P) is that P[0] = 2 , P[1] = 3 , P[2] = 5, and P[3] = 7 . The return value in this case would be true since all these divisions fail. Similarly to test m =143 , one must do trial divisions by 2, 3, 5, 7, and 11 (since 13 143 ). The precondition for the function call isPrime(143, P) is therefore P[0] = 2 , P[1] = 3 , P[2] = 5, P[3] = 7 , and P[4] =11. The return value in this case would be false since 11 divides 143. Function isPrime() should contain a loop that steps through array P, doing trial divisions. This loop should terminate when 2 either a trial division succeeds, in which case false is returned, or until the next prime in P is greater than m , in which case true is returned. Function main() in this project will read the command line argument n, allocate an int array of length n, fill the array with primes, then print the contents of the array to stdout according to the format described below. In the context of function main(), we will refer to this array as Primes[]. Thus array Primes[] plays a dual role in this project. On the one hand, it is used to collect, store, and print the output data. On the other hand, it is passed to function isPrime() to test new integers for primality. Whenever isPrime() returns true, the newly discovered prime will be placed at the appropriate position in array Primes[]. This process works since, as explained above, the primes needed to test an integer m range only up to m , and all of these primes (and more) will already be stored in array Primes[] when m is tested. Of course it will be necessary to initialize Primes[0] = 2 manually, then proceed to test 3, 4, … for primality using function isPrime(). The following is an outline of the steps to be performed in function main(). • Check that the user supplied exactly one command line argument which can be interpreted as a positive integer n. If the command line argument is not a single positive integer, your program will print a usage message as specified in the examples below, then exit. • Allocate array Primes[] of length n and initialize Primes[0] = 2 . • Enter a loop which will discover subsequent primes and store them as Primes[1] , Primes[2], Primes[3] , ……, Primes[n -1] . This loop should contain an inner loop which walks through successive integers and tests them for primality by calling function isPrime() with appropriate arguments. • Print the contents of array Primes[] to stdout, 10 to a line separated by single spaces. In other words Primes[0] through Primes[9] will go on line 1, Primes[10] though Primes[19] will go on line 2, and so on. Note that if n is not a multiple of 10, then the last line of output will contain fewer than 10 primes. Your program, which will be called Prime.java, will produce output identical to that of the sample runs below. (As usual % signifies the unix prompt.) % java Prime Usage: java Prime [PositiveInteger] % java Prime xyz Usage: java Prime [PositiveInteger] % java Prime 10 20 Usage: java Prime [PositiveInteger] % java Prime 75 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 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 % 3 As you can see, inappropriate command line argument(s) generate a usage message which is similar to that of many unix commands. (Try doing the more command with no arguments to see such a message.) Your program will include a function called Usage() having signature static void Usage() that prints this message to stderr, then exits. Thus your program will contain three functions in all: main(), isPrime(), and Usage(). Each should be preceded by a comment block giving it’s name, a short description of it’s operation, and any necessary preconditions (such as those for isPrime().) See examples on the webpage.

    Read the article

  • Compile a COM program

    - by Fantomas
    Can COM program be 32 bit? How can I compile COM program? I have TLINK32 and TASM32. tasm32 \t alex_7.asm pause tlink32 alex_7.obj pause td32 main.exe I ve got following error: Fatal: 16 bit segments not supported in module alex_7.asm I habe DOSBOX and I'am running Windows 7 x64

    Read the article

  • To specify Startup Program in C# Express Edition 2008

    - by Kanini
    I usually do the following at office - Set the startup program for the project to System32\dllhost.exe, and set the command line arguments for the startup program accordingly. This used to work perfectly fine, because I was running Visual Studio 2008. However, one of my developers use C# Express Edition and they need to do a similar thing. We are not sure, where to set this or how to do it? Please suggest how to do this or point us in the right directions.

    Read the article

  • C# program to switch updating from Master server to Slave server

    - by tanthiamhuat
    assuming that I have setup the Database (MySQL) Replication using Master-Slave configuration, and have synchronized those Master and Slave servers, how can my C# program know that it has to update the Slave server when the Master server fails? What are the conditions that the C# program switch from the Master server to the Slave server? I am using MySQL server.

    Read the article

  • How do I lock the layout of my android program to one orientation

    - by Mike V
    I'm trying to write a program that needs smooth orientation sensor samples as the phone is rotated all around. Every time the orientation of the phone is changed, it interrupts the data and freezes the program while the layout changes. How can I lock it in one orientation (landscape or portrait, it doesn't matter)? I assume it has something to do with android:layout in the xml file, but I can't find anything online.

    Read the article

  • This program has stopped working

    - by Isuru
    In a visual C++ mfc program, which I run on Wondows 7, I always get the error message This Program Has Stopped Working after I close the main dialog/exit the application. But it doesn't happen in Windows XP. Can anyone explain what the matter is and how to solve it? Thanks a lot.

    Read the article

  • time to run a program in C

    - by yCalleecharan
    Hi, I would like to know what lines of C code to add to a program so that it tells me the total time that the program takes to run. I guess there should be counter initialization near the beginning of main and one after the main function ends. Is the right header clock.h? Thanks a lot...

    Read the article

  • software program to help manage company [closed]

    - by chrissy
    Is there a software program for a company who publishes a newsletter with advertisers in it. One that keeps track of sales of advertisers, payments to salesforce, layouts/copy for the publication, accounting. Is there one program that takes care of all of that or are their seprate programs for each?

    Read the article

  • How can my-program.hs get its version number from my-program.cabal at build time?

    - by Dave Hinton
    I would like my cabalised program to have a --version switch. I would like it to report the same version as is present in the .cabal file. If I have to update the version number separately in my Haskell source code as well as in the .cabal file, I will eventually get them out of sync. So, how can my program, while being compiled under cabal, get its version number from the .cabal file?

    Read the article

  • program for calculating metrics in java

    - by senzacionale
    i need to calculate few metrics (CBO, NOC, DAC, LCOM, WMC, RFC and DIT metric). Program is written in jdeveloper and i do not know how to calculate this metrics. Migration to eclipse is not possible becouse code is not compiled. Does anyone know any good program for calculating metrics?

    Read the article

  • I can't get my Android program to run correctly on an AVM in Eclipse

    - by Wes
    This is a simple question about getting started with developing Android apps using Eclipse. I have followed all the tutorials on the developer site for installing Eclipse, the SDK and the ADT plugin. When trying to run a simple Hello World program, everything seems to compile correctly, but then the virtual machine comes up empty. In the Console Window it reads: The program then just sits and my text never comes up. Any idea with what the problem could be?

    Read the article

  • How to find where program crashed

    - by Mick
    I have a program that crashes (attempting to read a bad memory address) while running the "release" version but does not report any problems while running the "debug" version in the visual studio debugger. When the program crashes the OS asks if I'd like to open up the debugger, and if I say yes then I see an arrow pointing to where I am in a listing of some assembler which I am not skilled enough to read properly (I learned 6502 assembler 30 years ago). Is there any way for my to determine where in my sourcecode the offending memory read was located?

    Read the article

< Previous Page | 67 68 69 70 71 72 73 74 75 76 77 78  | Next Page >