Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

C – VERY-EASY – PART005-Print except multiples of N

 Two numbers A and B are passed as input. A number N is also passed as the input. The program must print the numbers from A to B (inclusive of A and B) which are not divisible by N.

Input Format:
The first line denotes the value of A.
The second line denotes the value of B.
The third line denotes the value of N.

Output Format:
The numbers from A to B (inclusive of A and B) which are not divisible by N, each separated by a space.

Boundary Conditions:
1 <= A <= 9999999
A <  B <= 9999999
1 <= N <= 9999

Example Input/Output 1:
Input:
3
20
5

Output:
3 4 6 7 8 9 11 12 13 14 16 17 18 19

Explanation:
The numbers 5 10 15 20 are left out as they are divisible by 5.

Code:

#include<stdio.h>
void countNumbers(int X, int Y, int N)
{
    for (int i = X; i <= Y; i++) {
        if (i % N == 0)
            continue;
        else
        printf("%d ",i);
    } 
}
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    countNumbers(a,b,c);
}

Post a Comment

Previous Post Next Post