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

INFEED

c++ very easy part 5 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<bits/stdc++.h>

using namespace std;

void countNumbers(int X, int Y, int N)
{
    for (int i = X; i <= Y; i++) {
        if (i % N == 0)
            continue;
        else
        cout<<i<<" ";
       
    }
}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    countNumbers(a,b,c);
}

Post a Comment

Previous Post Next Post