Question: Write a program that prompts the user to enter two integers. The program uses a loop to count how many numbers are multiples of 3

Write a program that prompts the user to enter two integers.

The program uses a loop to count how many numbers are multiples of 3 and how many numbers are multiples of 5 between the two integers (inclusive). Once all the multiples are counted, the program outputs the results.

For Example:

Enter two integers: -100 -10000

Number of multiples of 3 between -10000 and -100 is: 3300

Number of multiples of 5 between -10000 and -100 is: 1981

Here's my code:

#include

int main() {

int num1;

int num2;

int mul3=0;

int mul5=0;

printf("Enter two integers: ");

scanf("%d %d",&num1, &num2);

printf(" ");

for(int i=num1; i<=num2; i++){

if(i%3==0){

mul3++;

}

if(i%5==0){

mul5++;

}

}

if(num1>num2){

printf("Number of multiples of 3 between %d and %d is: %d ",num2,num1,mul3);

printf("Number of multiples of 5 between %d and %d is: %d ",num2,num1,mul5);

}

else{

printf("Number of multiples of 3 between %d and %d is: %d ",num1,num2,mul3);

printf("Number of multiples of 5 between %d and %d is: %d ",num1,num2,mul5);

}

return (0);

}

Here's my output:

Enter two integers: -100 -10000

Number of multiples of 3 between -10000 and -100 is: 0

Number of multiples of 5 between -10000 and -100 is: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!