Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions