Example Code

Calculate Prime Number in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW MathScript RT Module
  • LabVIEW

Code and Documents

Attachment

Overview

Demonstrates how to calculate 1001st prime number using MathScript Node.

 

Description

This program is to solve Project Euler Problem Number 7: By listing the first six prime numbers, what is the 10001st prime number? The example uses iteration number as the number to be computed. MathScript Node is used to determine whether the number is a prime number. The prime numbers identified is built into an array. The program stops when the prime numbers elements reach 1001. The last prime number will be displayed.

 

Requirements

LabVIEW 2012 (or compatible)

MathScript RT module

 

Steps to Implement or Execute Code

  1. Run the program
  2. The program takes a few seconds to compute the first 1001 prime numbers
  3. The 1001st prime number will be displayed

 

Additional Information or Resources

VI Block Diagram

 

BD.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

Rob W.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.