Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

100pts for completing both programs of this bonus assignment The grade for this

ID: 3760490 • Letter: 1

Question

100pts for completing both programs of this bonus assignment The grade for this bonus assignment replaces your lowest assignment grade 1. Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2, 2, 4)). Sample execution of the program for this array is given below Enter 7 numbers 1223431 Enter k 2 3 elements are divisible by 2 Write and implement the following functions in your program: int divisible(int a, int b) int count(int data[] ,int n, int k)

Explanation / Answer

#include<stdio.h>

int divisble(int a,int b)

{

return a%b;

}

int count(int data[],int n,int k)

{

int count_ = 0;

for(int i=0;i<n;i++)

if(divisble(data[i], k)==0)

count_++;

  

return count_;

}

int main()

{

int arr[7],k;

printf("Enter 7 numbers : ");

  

for(int i=0;i<7;i++)

scanf("%d",&arr[i]);

  

printf("Enter k: ");

scanf("%d",&k);

  

int count_ = count(arr,7,k);

  

printf("%d are divisible by %d",count_,k);

  

return 0;

  

}

OP:

Enter 7 numbers :

1 2 2 3 4 3 1

Enter k:

2

3 are divisible by 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote