Example: Find Out if a Given Number is Divisible by 3 in C# To check if number i
ID: 3765764 • Letter: E
Question
Example: Find Out if a Given Number is Divisible by 3 in C#
To check if number is divisible by 3 or not you have to use the mode operator and if reminder is 0 it means it is divisible.
using System;
namespace ConsoleHub {
class Programs {
static void Main(string[] args) {
Console.WriteLine("Enter a Number:");
int intDiv3 = Convert.ToInt16( Console.ReadLine()); if (intDiv3 % 3 == 0)
{
Console.WriteLine("The Number {0} is Divisible by 3", intDiv3); }
else {
Console.WriteLine("The Number {0} is NOT Divisible by 3", intDiv3); }
Console.ReadLine(); }
} }
Project :
Create a program for checking the exact division between any two numbers. The numbers will be entered from the console.
Explanation / Answer
using System;
namespace ConsoleHub {
class Programs {
static void Main(string[] args) {
Console.WriteLine("Enter Number 1 :");
int number1 = Convert.ToInt16( Console.ReadLine());
Console.WriteLine("Enter Number 2 :");
int number2 = Convert.ToInt16( Console.ReadLine());
int a,b;
if(number1>=number2)
{
a = number1;
b = number2;
}
else
{
a = number2;
b = number1;
}
if(a%b==0)
{
Console.WriteLine("The Number {0} is Divisible by {1}", a,b); }
else {
Console.WriteLine("The Number {0} is NOT Divisible by {1}", a,b); }
Console.ReadLine(); }
} }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.