Home
Aptitude
Categories


Home » C programs » C One Dimensional Array programs

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.