Answer to Question #296009 in C for RUNJHUN

Question #296009

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-02-10T07:12:36-0500
#include <stdio.h>


int count(int* A, int N, int X, int Y) {
    int num, i;


    num = 0;
    for (i=0; i<N; i++) {
        if (A[i] <= X && A[i] % Y == 0) {
            num++;
        }
    }
    return num;
}


int main() {
    int A[] = { 3, 5, 6, 7, 10, 20, 15, 21, 48, 6};
    int n = sizeof(A) / sizeof(A[0]);
    int x = 20, y = 3;
    int num;


    num = count(A, n, x, y);
    printf("There are %d numbers less or equal %d and divided by %d in the array.\n",
            num, x, y);
    
    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