C#: Test whether a given non-negative number is a multiple of 13 or it is one more than a multiple of 13
C# Sharp Basic Algorithm: Exercise-42 with Solution
Multiple of 13 or 1 More
Write a C# Sharp program to test if a given non-negative number is a multiple of 13 or one more than a multiple of 13.
Sample Solution:-
C# Sharp Code:
using System;
using System.Linq;
namespace exercises
{
// Class declaration
class Program
{
// Main method - entry point of the program
static void Main(string[] args)
{
// Calling the 'test' method with different integers and printing the results
Console.WriteLine(test(13)); // Output: True
Console.WriteLine(test(14)); // Output: True
Console.WriteLine(test(27)); // Output: False
Console.WriteLine(test(41)); // Output: True
Console.ReadLine(); // Keeping the console window open
}
// Method to check if a number is either a multiple of 13 or has a remainder of 1 when divided by 13
public static bool test(int n)
{
// Check if the remainder when 'n' is divided by 13 is either 0 or 1
return n % 13 == 0 || n % 13 == 1;
}
}
}
Sample Output:
True True True False
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program that accept two integers and return true if either one is 5 or their sum or difference is 5.
Next: Write a C# Sharp program to check if a given non-negative given number is a multiple of 3 or 7, but not both.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/csharp-exercises/basic-algo/csharp-basic-algorithm-exercises-42.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics