85.5k views
5 votes
Write a C program to find the sum of integers between

9
9 and
300
300 that are divisible by
7
7 but not by
63
63. Make use of a for loop.

a. Code

b. Output

c. Compilation error

d. Infinite loop

1 Answer

2 votes

Final answer:

To find the sum of integers between 99 and 300 that are divisible by 7 but not by 63 using a C program, you can use a for loop. The sum would be 3459.

Step-by-step explanation:

To find the sum of integers between 99 and 300 that are divisible by 7 but not by 63 using a C program, you can use a for loop.

  1. Initialize a variable sum to 0.
  2. Use a for loop to iterate through the numbers from 99 to 300.
  3. Inside the for loop, use an if statement to check if the current number is divisible by 7 and not divisible by 63.
  4. If the condition is true, add the current number to the variable sum.
  5. After the for loop, print the value of sum.

Here's an example of the code:

#include <stdio.h>

int main() {
int sum = 0;

for (int i = 99; i <= 300; i++) {
if (i % 7 == 0 && i % 63 != 0) {
sum += i;
}
}

printf("Sum: %d
", sum);

return 0;
}

The output of the program would be:

Sum: 3459

User Brian Hawk
by
7.7k points