Question: Check for divisibility by 3, 5 and 7
Request an integer from user and display whether the number is divisible by 3, 5 and 7.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mod_Function_Ex_2
{
class Program
{
static void Main(string[] args)
{
repeat:
int Mod3, Mod5, Mod7;
Console.Write("Enter a value: ");
int userInput = int.Parse(Console.ReadLine());
Mod3 = userInput % 3;
Mod5 = userInput % 5;
Mod7 = userInput % 7;
if(Mod3 == 0 || Mod5 == 0 || Mod7 == 0)
{
if (Mod3 == 0)
{
Console.WriteLine("Your number is divisible by 3");
}
if (Mod5 == 0)
{
Console.WriteLine("Your number is divisible by 5");
}
if (Mod7 == 0)
{
Console.WriteLine("Your number is divisible by 7");
}
}
else
{
Console.WriteLine("Your number is not divisible by any of 3, 5 and 7");
}
Console.WriteLine("\nHit enter to continue");
Console.ReadLine();
Console.Clear();
goto repeat;
}
}
}
No comments:
Post a Comment