C Program to count divisors : HackerEarth

Question: You have been given 3 integers - l, r and k. Find how many numbers between l and r (both inclusive) are divisible by k. You do not need to print these numbers, you just have to find their count.


Code:

main()
{
    int num1,num2,k,count,i;
    scanf("%d %d %d",&num1,&num2,&k);
    for(i=num1;i<=num2;i++)
    {
        if(i%k==0)
        {
            count++;
        }
    }
    printf("%d",count);
}


Output:


C Program to count divisors : HackerEarth C Program to count divisors : HackerEarth Reviewed by Prashant Sengar on January 01, 2018 Rating: 5

No comments:

Powered by Blogger.