Answer to Question #322328 in C for Vedant

Question #322328

Given an array A of N integers and two integers X and Y, find the number of integers in the array that are both less than or equal to X and divisible by Y

1
Expert's answer
2022-06-28T08:19:33-0400
#include <stdio.h>

int main()
{
  const int n = 10;
  const int a[] = {4, 7, 2, -2, 5, 10, 11, 0, 2, 1};
  const int x = 6;
  const int y = 2;
   
  int c = 0;
  for (int i = 0; i < n; i++)
    if (a[i] <= x && a[i] % y == 0)
      c++;
   
  printf("%d", c);

  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS