Q:

C program to count total number of elements divisible by a specific number in an array

0

C program to count total number of elements divisible by a specific number in an array

Given an array arr and number b, we have to count total number of elements divisible by b.

Example:

    Input:
    Enter array elements:
    10
    15
    20
    25
    30

    Number: 10

    Output:
    Total elements divisible by 10 is 3

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

One Dimensional Array Programs / Examples in C programming language

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to create a new array from a given array... >>
<< C program to create array with reverse elements of...