Computer Science, asked by akshayamani1998, 11 months ago

THE PROGRAM MUST ACCEPT N INTEGERS AND TWO INTEGERS X,Y AS THE INPUT . THE PROGRAM MUST PRINT THR INTEGERS WHICH ARE HAVING EXACTLY X DIGITS AND ALSO DIVISIBLE BY Y AMONG THE N INTEGERS AS THE OUTPUT . IF THERE IS NO SUCH INTEGER ,THE PROGRAM MUST PRINT -1 AS THE OUTPUT​

Answers

Answered by syed2020ashaels
0

Answer:

To count numbers divisible by X but not Y, simply loop through 1 to N and count any number that is divisible by X but not Y.

Explanation:

Approach

  1. Increment the count for each number in the range 1 to N if it is divisible by X but not by Y.
  2. Print the total.

The above approach is implemented as follows:

// C++ implementation of above approach

#include <bits/stdc++.h>

using namespace std;

// Function to count total numbers divisible by

// x but not y in range 1 to N

int countNumbers(int X, int Y, int N)

{

int count = 0;

for (int i = 1; i <= N; i++) {

 // Check if Number is divisible

 // by x but not Y

 // if yes, Increment count

 if ((i % X == 0) && (i % Y != 0))

  count++;

}

return count;

}

// Driver Code

int main()

{

int X = 2, Y = 3, N = 10;

cout << countNumbers(X, Y, N);

return 0;

}

For similar questions refer-https://brainly.in/question/16594209

#SPJ1

Similar questions