Determine smallest single-digit factor. : Remainder Operator : Operator C# Examples


C# Examples » Operator » Remainder Operator »

 

Determine smallest single-digit factor.









    
using  System;  
  
class    MainClass  {        
    public  static  void  Main()  {        
        int  num;  
  
        for(num  =  2;  num  <  12;  num++)  {  
            if((num  %  2)  ==  0)  
                Console.WriteLine("Smallest  factor  of  "  +  num  +  "  is  2.");    
            else  if((num  %  3)  ==  0)    
                Console.WriteLine("Smallest  factor  of  "  +  num  +  "  is  3.");    
            else  if((num  %  5)  ==  0)  
                Console.WriteLine("Smallest  factor  of  "  +  num  +  "  is  5.");    
            else  if((num  %  7)  ==  0)    
                Console.WriteLine("Smallest  factor  of  "  +  num  +  "  is  7.");    
            else    
                Console.WriteLine(num  +  "  is  not  divisible  by  2,  3,  5,  or  7.");    
        }  
    }  
}
    
   
  
   



Output

Smallest factor of 2 is 2.
Smallest factor of 3 is 3.
Smallest factor of 4 is 2.
Smallest factor of 5 is 5.
Smallest factor of 6 is 2.
Smallest factor of 7 is 7.
Smallest factor of 8 is 2.
Smallest factor of 9 is 3.
Smallest factor of 10 is 2.
11 is not divisible by 2, 3, 5, or 7.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Remainder Operator