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

Here, we are implementing a c program that will count total number of elements divisible by a specific number in an array.
Submitted by IncludeHelp, on December 04, 2018

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

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

C One-Dimensional Array Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.