Primality Test | Set 1 ( Introduction and School Method ) | A optimized school method based C # program to check if a number is prime ; Corner cases ; Check from 2 to n - 1 ; Driver program
using System ; namespace prime { public class GFG { public static bool isprime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } public static void Main ( ) { if ( isprime ( 11 ) ) Console . WriteLine ( " true " ) ; else Console . WriteLine ( " false " ) ; if ( isprime ( 15 ) ) Console . WriteLine ( " true " ) ; else Console . WriteLine ( " false " ) ; } } }