Saturday, March 2, 2013

Finding Prime Number using LabVIEW


Finding whether a number is prime or not

 Hi Guys, i had done some basic VI programming, since i wanted it to share i am starting with this post.

Well, here’s the program which I did for finding whether its prime or not, i have used for loop to build a logic for this program.
Prime Number
Front Panel and Block diagram Panel for this program
  • Firstly, i took 'for loop' and gave 10 for count terminal and for the iteration i added with 2, since it starts from 0.
  • Then i took the 'Quotient and Remainder' from 'Numeric'.
  • Here i gave the iteration terminal 'i' to the shift register and also initialized the register as 1.
  • Now, i connected the shift register to the denominator of 'Q&R' function.
  • An Numeric control is connected to the numerator
  • Now, after the division, if the remainder is 0, the output becomes true and is converted to 1 and is summed by the 'Add Array Elements'. 
  • Thus the logic is if the sum of 1 exceeds 2 then it is not a prime number and if it is less than or equal to, then it is a prime number.
Above steps are the logic for 'finding whether it is prime or not' program and here is the working video of that program...

You may also download the original file by clicking on the link shown below
http://www.sendspace.com/file/8cl2ds

This is it of now, will post other logic in the next post....Till then

Greetings From
KiranSravan

4 comments:

  1. 723 is not a prime number.... 723 / 3 = 241

    ReplyDelete
  2. Above comment was in reference to entry at 0:29 seconds into video. Also, if 39 is entered, this program will find it to be a prime number even though it is not. The reason for this is that the loop only iterates 10 times, meaning it never divides a number by a denominator greater than 10. In the case of 39, only 1 and 3 are detected as having no remainder. Had the loop iterated to 13, that would have been detected as well as a multiple of 39, which would have made the array sum greater than 2. The problem with this code is if a number is divisible by a prime number greater than 10, it may incorrectly show it as prime.

    ReplyDelete
    Replies
    1. Yes, the iteration value should be increased. I didn't notice while uploading...Anyways thanks for pointing out the mistake mate

      Delete
  3. Kindly tell if we use the square root of the number as the count terminal, would it be correct? If yes do we need to change it to an integer(using gint maybe) before giving it as count terminal or would it work without doing so?

    ReplyDelete