Like Tree1Likes

programme, prime factorisation

This is a discussion on programme, prime factorisation within the C Programming forums, part of the General Programming Boards category; I'm talking about your algorythm. Is the whole algorythm about copying?...

  1. #16
    Registered User
    Join Date
    Jan 2013
    Posts
    7
    I'm talking about your algorythm. Is the whole algorythm about copying?

  2. #17
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Good Sorry, for being suspicious, but some users just copy paste someone's code and come here pretending it is theirs.. How could someone do this and feel right???

    Anyway, in my example, you just open two files, like you have done nicely in your code too.
    Then it reads the 1st line and will write this 1st line (from the source file) to the output file.
    Then it reads the 2nd line and will write this 2nd line (from the source file) to the output file.
    It will keep doing the same, until EOF is reached.
    Then we close both file pointers.

    Notice, that in my example, we copy all the data of the source file to the output file. In your case you want to read data, do the prime thing and then write the b array in the output file.
    So, I suggest you to do the prime job inside a loop (where you will read a line per loop from the source file) and within that loop you will fill your array b.
    Then when the loop is terminated, thus we reached EOF, you will call fwrite just once and write the whole array b in the output file (just with one call).
    Also declare the array b outside the loop.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #18
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305
    Hint:
    Code:
    while ((a[i]% j) == 0)
    For this loop not to be infinite (assuming it is entered), then either a, i, a[i], or j is going to have to change inside the loop.
    stahta01 likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is a number Prime or not prime?
    By ImaCnoob in forum C Programming
    Replies: 27
    Last Post: 10-08-2012, 11:47 PM
  2. Replies: 1
    Last Post: 03-16-2012, 02:07 AM
  3. prime factorisation program
    By szpengchao in forum C Programming
    Replies: 4
    Last Post: 04-07-2009, 04:30 PM
  4. Replies: 3
    Last Post: 03-29-2005, 03:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21