How to get number of digits divisible by 5

list of numbers divisible by 5
c program to print numbers divisible by 3 and 5
count the numbers divisible by ‘m’ in a given range
how to find the number of values in a given range divisible by a given value?
is 5 divisible by 5
list of numbers divisible by 3
list of numbers divisible by 6
c# divisible by 5

I want to find the total number of digits divisible by 5 between 1 - 100, in C# windows form, how to proceed from here?

int sum;
private void button2_Click(object sender, EventArgs e)
{
    int[] intarray = new int[100];

    for (int i = 0; i < 99; i++)
    {
        intarray[i] = i + 1;
    }

    foreach (int a in intarray)
    {
        if (a / 5 == 0)
        {

        }

    }
}

Initialize a variable as 0

for e.g. Count = 0;

then add statement Count++ in your if block as follows:

            if (a % 5 == 0)
            {
                  Count++;
            }

How to get number of digits divisible by 5, Given number of digit n and a number, the task is to count all the numbers which are divisible by that number and having n digit. N digit numbers divisible by 5 formed from the M digits · Count n digit numbers not having a particular digit  Step 1: Adding the digits in the given number we get, 4+5+1+3=13 Step 2: We know that 13 is not divisible by 9. Step 3: Thus, we can say that the given number is not exactly divisible by 9. Example 2: Is 3555 divisible by 9? Step 1: Adding the digits in the given number we get, 3+5+5+5=18 Step 2: We know that 18 is exactly divisible by 9.

Note than a / 5 == 0 is wrong. For example 10 is divisible by 2, the result is 10/5 = 2, not equal to 0.

if (a % 5 == 0)
{
    //then a is divisible by 5. print or store it
}

The modulus operator, also known as Remainder, returns the remainder of the integer division.

Therefore, the full answer:

int nInRange = 0;
foreach (int a in intarray)
    if (a % 5 == 0)
        nInRange++;

Count n digit numbers divisible by given number, But, Count should be 5. Thus, we will add 1 explicitly. Below is the implementation of the above method : C/C++. According to the condition the number must be divisible by 5 , So , the last digit must be 0 or 5. Let us divide it into 2 parts and then we shall use the addition rule to get the final answer. Part A will the numbers having 0 at end and Part B will be the numbers having 5 at end.

Maybe this is what you want.

public static IEnumerable<int> GetIntsDivisible(int start, int finish, int divisor)
{
    for (var i = start; i <= finish; i++)
        if (i % divisor == 0)
            yield return i;
}
public static void Main()
{
    Console.WriteLine(string.Join(", ", GetIntsDivisible(1, 100, 5)));
}

or if you don't want to yield

public static List<int> GetIntsDivisible(int start, int finish, int divisor)
{
    var result = new List<int>();
    for (var i = start; i <= finish; i++)
        if (i % divisor == 0)
            result.Add(i);
    return result;
}

Output

5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100

Full demo here

Count the numbers divisible by 'M' in a given range, Every number with 0 as a last digit is also divisible by 5, because we can represent it as a sum of Move the decimal point one place to the left and you get 68.4. A.P=100,105,110,………..,995 Therefore,a=100 d=5 a+(n-1)d=995 100+(n-1)(5)=995 (n-1)(5)=895 (n-1)=179 n=180 Therefore ,there are 180 three digit numbers which are

Since question is a bit vague in exact requirement, I will write the basic logic that can find the numbers exactly divisible by other number.

There is something called modulus (%) operator. It gives you the remainder of division.e.g. 11%5 will be 1, 13%5 will be 3, whereas 15%5 will be 0

so logic goes like,

for(int i=0;i<=100;i++) 
{
     if((i%5)==0)
     {
        \\this is ur number
     }
}

Divisibility by 5, Multiply and Divide by 5 Quickly, You might have to try each possibility and work from there. Victoria. Hi Greg. The 5 digit number is divisible by 5, and only a number ending in zero or five is  The greatest 5 digit number is 99999 since the number should be divisible by12, 15, 36 it should also be divisible by the lcm of 12,15,36.as lcm of these number is 180 so simply divide 99999 by 180. After dividing subtract the remainder from 99999.your answer will be 99900

Every one has address your question but no one talk about this weird attempt. I really think you should take 5 minute and read your code because you are just running everywhere.

You should take the pen and paper before going head first into coding. Here is a simple reading of your code so you understand what you were doing.

Line 1:

int[] intarray = new int[100];

So you start win an array, I guess it's for the result, right ? You will not be storing the number from 1 to 100 for no reason?

Line 2:

for (int i = 0; i < 99; i++)

Now we count from 0 to 98, I though it was form 1 to 100 .. Yes 98 as you are using < instead of <=

Line 3:

intarray[i] = i + 1;

Why ? 3rd line and you are already lost! You are filling the array with number you just iterate. It's like filling a bottle with water, then use it to fill an other bottle because you needed water. If you iterate from 1 to 100 you could have check if it was divisible.

for (int i = 1; i <= 100; i++)

Line 4:

foreach (int a in intarray)

Again ? We are back counting from 1 to 100..

Line 5:

if (a / 5 == 0)

If this is suppose to tell you if it divisible thats wrong. The correct math operator is the Modulo. The division symbole won't give you the result you expect. {1,2,3,4} will give you True. Anything else will be false.

Show that there is no five-digit number which , A divisibility rule is a shorthand way of determining whether a given integer is divisible by a fixed divisor without performing the division, usually by examining its digits. Although there are divisibility tests for numbers in any radix, or base, and they Note: To test divisibility by any number that can be expressed as 2n or 5n,  Program to print series of number divisible by 5 and 7 - Duration: 3:17. Maitreyi App 8,668 views

Divisibility tests for 2, 3, 4, 5, 6, 9, 10 (video), How many 6 digit numbers can we form by using the digits 0−9 so that their sum of the digits is divisible by 5 I tried solving it by making cases for every 6  Check if any number is divisible by two. Type in any number that you want, and the calculator will use the rule for divisibility by 2 to explain the result. See what the rule for divisibility by two has to say about the following number: Examples of numbers that are do not pass this divisibility test because they are not even.

Divisibility rule, Find a nine-digit number such that the first digit is divisible by one, the first two the next digit (again, I'll call it ?) on the end and divide again, I'll get 5? for the  Determine whether the number 456 is divisible by 6. The test for determining whether a number is divisible by 6 is twofold. First determine whether the number is even. 456 is even, since it ends in 6. Then, determine whether the sum of the digits is divisible by 3. So, you would calculate + + =. The number 15 is divisible by 3.

Sum of Digits divisible by 5, For reasons I'll explain below the question if you're interested, I stumbled across a peculiar phenomenon involving numbers divisible by their digits. I'm concerned with numbers that are divisible by all of its digits, and do not have any zeros or repeated digits. Ex: 175, 9867312, 1. Not: 111, 105

Comments
  • int result = 100/5;?
  • please mention your scenario clearly and ask specific question. And also you don't need an array to store values from 1 to 100.
  • Well, 100/5 will tell you how many numbers are divisible by 5 in the range [0;100] and it's the same for [1;100]
  • 5 is divisible by 5 and 5 / 5 == 1. Rather use modulo operator. 5 % 5 == 0
  • You should really use paper and pen befor heading head first into coding. Nothing in the code make sense. even 10 years old scratch program are mutch more logic.
  • 5 / 5 is 1 not 0.
  • do we use % sign as divide in C# ? Isn't / real divide sign?
  • % is the modulo operator. It's a basic math operator.
  • I never understood how to use yield. Does, in that case and since the function is typed IEnumerable<int>, each yield return i; will act like .Add(i); ?
  • @Cid yes basically, when it gets enumerated over it will yield each element , or when you ToList();
  • What is the advantage using yield over returning a List<T> ?
  • @Cid none really, its just a different way of doing it, it just yields while you are enumerating over it. you could also just as easily create a list and return that, in some situations yield is more elegant
  • Thanks for your explanations, it became more clear. By the way, I suggest you to edit your post and to replace if (i % 5 == 0) by if (i % divisor == 0) since it's the purpose of the argument.