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

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.

This question is related to c#

The answer is


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 )  ....

there are some syntax errors to your program heres a working code;

#include<stdio.h>
int main()
{
int a,b;
printf("enter any two number\n");
scanf("%d%d",&a,&b);
if (a%b==0){
printf("this is  multiple number");
}
else if (b%a==0){
printf("this is multiple number");
}
else{
printf("this is not multiple number");
return 0;
}

}


Use the modulus (%) operator:

6 % 3 == 0
7 % 3 == 1

followings programs will execute,"one number is multiple of another" in

#include<stdio.h>
int main
{
int a,b;
printf("enter any two number\n");
scanf("%d%d",&a,&b);
if (a%b==0)
printf("this is  multiple number");
else if (b%a==0);
printf("this is multiple number");
else
printf("this is not multiple number");
return 0;
}

bool isMultiple = a % b == 0;

This will be true if a is a multiple of b