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

Computer Programming with Engineering Applications Assignment 4 1. (100 pts) Wri

ID: 641469 • Letter: C

Question


Computer Programming with Engineering Applications Assignment 4 1. (100 pts) Write a program that reads an integer k from user and finds the number of elements that are divisible by k in the file assign4.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 assign4.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 10

Explanation / Answer

#include "stdafx.h"
#include "stdio.h"

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

int main(void)
{
int num, divider, counter = 0;
FILE * list;
FILE * output;
list = fopen("assign4.txt", "r");
output = fopen("output.txt", "w");

printf("Enter a number: ");
scanf("%d", &divider);
while (fscanf(list, "%d", &num) != EOF)
{
if (num % divider == 0)
{
counter++;
fprintf(output, "%d ", num);
}
}
printf("%d numbers are divisible by %d ", counter, divider);
return 0;
}

assign4.txt

38

86

49

67

84

60

43

83

37

66

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote