C# How to determine if a number is a multiple of another?

前端 未结 6 1815
梦毁少年i
梦毁少年i 2020-12-28 13:50

Without using string manipulation (checking for an occurrence of the . or , character) by casting the product of an int calculation to string.

6条回答
  •  温柔的废话
    2020-12-28 14:27

    I don't get that part about the string stuff, but why don't you use the modulo operator (%) to check if a number is dividable by another? If a number is dividable by another, the other is automatically a multiple of that number.

    It goes like that:

       int a = 10; int b = 5;
    
       // is a a multiple of b 
       if ( a % b == 0 )  ....
    

提交回复
热议问题