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.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int main(){
int size;
int X;
int Y;
int i;
int counter=0;
int numbers[1000];
printf("Enter the size of the array: ");
scanf("%d",&size);
for(i=0;i<size;i++){
printf("Enter the number %d: ",(i+1));
scanf("%d",&numbers[i]);
}
printf("Enter X: ");
scanf("%d",&X);
printf("Enter Y: ");
scanf("%d",&Y);
for (i = 0; i < size; i++) {
if (numbers[i] <= X && numbers[i] % Y == 0) {
counter++;
}
}
printf("The number of integers in the array that are both less than or equal to %d and divisible by %d: %d\n",X,Y,counter);
getchar();
getchar();
return 0;
}
Comments
Leave a comment