Given an array arr and number b, we have to count total number of elements divisible by b.
给定数组arr和数字b ,我们必须计算被b整除的元素总数。
Example:
例:
Input:
Enter array elements:
10
15
20
25
30
Number: 10
Output:
Total elements divisible by 10 is 3
Program:
程序:
/*
C program to count total number of elements
divisible by a specific number in an array
*/
#include <stdio.h>
#define MAX 5
int main(){
int arr[MAX]={0};
int i;
int b=10;
int count=0;
printf("Enter array elements:\n");
for(i=0; i<MAX; i++){
scanf("%d", &arr[i]);
if(arr[i]%b ==0)
count++;
}
printf("Total elements divisible by %d is %d\n",b, count);
return 0;
}
Output
输出量
Enter array elements:
10
15
20
25
30
Total elements divisible by 10 is 3