Computer Programming with Engineering Applications Bonus Questions 100pts for co
ID: 3769504 • Letter: C
Question
Computer Programming with Engineering Applications Bonus Questions 100pts for completing both programs of this bonus assignment The grade for this bonus assignment replaces your lowest assignment grade 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. 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 1 2 2 3 4 3 1 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) The function divisible returns 1 if a is divisible by b and 0 otherwise. The function count returns the number of elements divisible by k in array data. Use the function divisible in function count. Name your program bonus1.c and submit your program electronically using the blackboard system.Explanation / Answer
import java.io.*;
class bonus1{
public static void main(String[] args) throws IOException{
int i=0,n=0,k,a,c=0,cnt=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] arr=new int[7];
System.out.println("Enter nos:");
for(i=0;i<7;i++)
{
arr[i]=Integer.parseInt(br.readLine());
}
System.out.println("Enter K:");
k=Integer.parseInt(br.readLine());
for(i=0;i<7;i++)
{
a=arr[i];
if(a%k==0)
{
cnt=cnt+1;
}
}
System.out.println(cnt+" Elements divisible by"+k);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.