w3resource

C Exercises: Calculate the sum of all number not divisible by 17 between two given integer numbers

C Basic Declarations and Expressions: Exercise-39 with Solution

Write a C program to calculate the sum of all numbers not divisible by 17 between two given integer numbers.

C Programming: Calculate the sum of all number not divisible by 17 between two given integer numbers

Sample Solution:

C Code:

#include <stdio.h>
int main() {
    int x, y, temp, i, sum=0;

    // Prompt for user input
    printf("\nInput the first integer: ");
    scanf("%d", &x);
    printf("\nInput the second integer: ");
    scanf("%d", &y);

    // Swap values if x is greater than y
    if(x > y) {
        temp = y;
        y = x;
        x = temp;
    }

    // Calculate the sum of numbers not divisible by 17
    for(i = x; i <= y; i++) {
        if((i % 17) != 0) {
            sum += i;
        }
    }

    // Display the sum
    printf("\nSum: %d\n", sum);

    return 0;
}

Sample Output:

Input the first integer: 50                                            
                                                                       
Input the second integer: 99                                           
                                                                       
Sum: 3521

Flowchart:

C Programming Flowchart: Calculate the sum of all number not divisible by 17 between two given integer numbers

C Programming Code Editor:

Previous: Write a program that reads two numbers and divide the first number by second number. If the division not possible print "Division not possible".
Next: Write a C program to find all numbers which dividing it by 7 and the remainder is equal to 2 or 3 between two given integer numbers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-39.php