Write a program to accept two numbers and check if the first is divisible by the second. In addition, an error message should be displayed if the second number is zero.
Sample Solution
C# Sharp Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int n1, n2, result; Console.WriteLine("Enter First Number"); n1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Socond Number"); n2 = Convert.ToInt32(Console.ReadLine()); if (n2 == 0) { Console.WriteLine("you cannat divide by 0"); } else { result = n1 % n2; if (result == 0) Console.WriteLine("Divisible"); else Console.WriteLine("Not divisible"); } Console.ReadLine(); } } }
Sample Output
Second Output
Third Output
No comments:
Post a Comment