Write a program that reads an integer k from user and finds the number of elemen
ID: 3531868 • Letter: W
Question
Write a program that reads an integer k from user and finds the number of elements that are divisible by k in the file assign txt. A number n is divisible by k if n = kx for some integer x > 0. You can use the mod operator % to test for divisibility. The file assign txt has integer values in the range [0/100]. You should use end of file controlled loop for this problem. Sample execution is given below. Consider the file below 90 23 74 83 The output to be displayed on screen for the above file is Enter k 10 1 numbers are divisible by 10Explanation / Answer
#include<stdio.h>
int main()
{
FILE *infile;
int k,number,count=0;;
printf( "enter the value of k ");
scanf(" %d",&k);
infile = fopen("assign4.txt", "r");
while( fscanf(infile, "%d,", &number) > 0 )
{
if(number == 0) count++;
}
printf(" %d number divisible by %d" , count,k);
fclose(infile);
return 0;
}
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.