Knowee
Questions
Features
Study Tools

rite a C program requesting users to enter any two positive integers. Please find the sum ofall integers between these two numbers that can be divided (divisible) by four (4)

Question

rite a C program requesting users to enter any two positive integers. Please find the sum ofall integers between these two numbers that can be divided (divisible) by four (4)

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C program that does what you asked for:

#include <stdio.h>

int main() {
    int num1, num2, i, sum = 0;

    printf("Enter two positive integers: ");
    scanf("%d %d", &num1, &num2);

    if(num1 > num2) {
        int temp = num1;
        num1 = num2;
        num2 = temp;
    }

    for(i = num1; i <= num2; i++) {
        if(i % 4 == 0) {
            sum += i;
        }
    }

    printf("The sum of all integers between %d and %d that are divisible by 4 is: %d\n", num1, num2, sum);

    return 0;
}

This program first asks the user to input two positive integers. It then checks if the first number is greater than the second, and if it is, it swaps them. This is to ensure that the loop starts from the smaller number and ends at the larger number.

The program then loops from the smaller number to the larger number, and for each number, it checks if it is divisible by 4. If it is, it adds it to the sum. Finally, it prints out the sum.

This problem has been solved

Similar Questions

Write a C program requesting users to enter any two positive integers. Please find the sum ofall integers between these two numbers that can be divided (divisible) by four (4).Your program should validate that both numbers are positive. If it is not so, inform the user untilhe enters a positive integer. The user can enter a larger number as the first integer and a smallernumber as the second intege

The program must accept four integers a, b, c and d as input. The program must solve the equation b * c - (a + d) and print it as the output.

Select the correct answerTwo different numbers when divided by a divisor left reminder 11 and 21 respectively. When their sum was divided by the same divisor reminder was 4. what is the divisor?Options89351528

Find the sum of all four-digit numbers that can be made using thedigits 1, 2, 3 and 4 without restriction.

The quotient of two numbers is 4. Their sum is 5. What are the two numbers?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.