Prime Number

Pirmae number is a number which can divisible by 1 and itself
Example : 3,7,5,11,13 etc

import 'dart:io';//1

  var isPrime=true;//2
  print("Enter a Integer Value");//3

      var value = int.parse(stdin.readLineSync());//4
      for(int i=2;i<value-1;i++)//5
                isPrime = false;//7

           print("Entered Number is Prime $value");//10
          print("Entered Number is not  Prime $value");//11
  1. import statement for input and out-stream lib for Dart
  2. Take the isPrime variable and assign true value
  3. Instruct to user enter a number
  4. Take input from a user and convert into int and assign to value
  5. Execute for loop from 2 and value-1
  6. Each irritation of for loop check entered value is divisible with another number
  7. if statement result is true then the value of isPrime is changed to false
  8. Terminate the for loop immediately
  9. check is the isPrime value for true or false
  10. if isPrime value is true then if block executes and prints the result
  11. if isPrime value is false then else block executes and print the result


Enter an Integer Value
Entered Number is not Prime 45

Enter an Integer Value
Entered Number is Prime 3

Leave a Reply

Your email address will not be published. Required fields are marked *