Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

and

without using try / catch scenarios relying on errors from data types.

How do you specifically check using C# if a number is a multiple of another?

For example 6 is a multiple of 3, but 7 is not.

like image 882
JL. Avatar asked Jul 09 '10 20:07

JL.


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C full form?

Originally Answered: What is the full form of C ? C - Compiler . C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.


1 Answers

Try

public bool IsDivisible(int x, int n) {    return (x % n) == 0; } 

The modulus operator % returns the remainder after dividing x by n which will always be 0 if x is divisible by n.

For more information, see the % operator on MSDN.

like image 97
Samuel Jack Avatar answered Oct 11 '22 22:10

Samuel Jack