Question

8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...

8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by either 3 or 7.
​ (b) Write a program that prints all of the numbers from 0 to 102 divisible by both 3 and 7
(c) Write a program that prints all of the even numbers from 0 to 102 divisible by both 3 and 7
(d) Write a program that prints all of the odd numbers from 0 to 102 divisible by both 3 and 7
(e) Write a program that prints all of the even numbers from 30 to 102 divisible by either 3 or 7
(f) Write a program that prints all of the odd numbers from 28 to 102 divisible by either 3 or 7
(g) Write a program that prints all of the odd numbers between 30 to 102 divisible by both 3
​​and 7. in loops
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a) Write a program that prints all of the numbers from 0 to 102 divisible by either 3 or 7.
Program:

#include <stdio.h>

int main()
{
int i = 0;
       printf("Numbers from 0 to 102 divisible by either 3 or 7 : ");
       for (i = 0; i <= 102; i++) {
           if ((i % 3 == 0) || (i % 7 == 0)) {
               printf("%d\t",i);
           }
       }
      

return 0;
}

Output:
Numbers from 0 to 102 divisible by either 3 or 7 : 0   3   6   7   9   12   14   15   18   21   24   27   28   30   33   35   36   39   42   45   48   49   51   54   56   57   60   63   66   69   70   72   75   77   78   81   84   87   90   91   93   96   98   99   102  

(b) Write a program that prints all of the numbers from 0 to 102 divisible by both 3 and 7
Program:

#include <stdio.h>

int main()
{
int i = 0;
       printf("\nNumbers from 0 to 102 divisible by either 3 and 7 : ");
       for (i = 0; i <= 102; i++) {
           if ((i % 3 == 0) && (i % 7 == 0)) {
               printf("%d\t",i);
           }
       }
      
return 0;
}
Output:
Numbers from 0 to 102 divisible by either 3 and 7 : 0   21   42   63   84  

(c) Write a program that prints all of the even numbers from 0 to 102 divisible by both 3 and 7
Program:

#include <stdio.h>
int main()
{
int i = 0;
       printf("\nEven numbers from 0 to 102 divisible by either 3 and 7 : ");
       for (i = 0; i <= 102; i++) {
           if (((i % 3 == 0) && (i % 7 == 0)) && (i % 2 == 0)) {
               printf("%d\t",i);
           }
       }  

return 0;
}
Output:
Even numbers from 0 to 102 divisible by either 3 and 7 : 0   42   84  
(d) Write a program that prints all of the odd numbers from 0 to 102 divisible by both 3 and 7
Program:

#include <stdio.h>
int main()
{
int i = 0;
       printf("\nOdd numbers from 0 to 102 divisible by either 3 and 7 : ");
       for (i = 0; i <= 102; i++) {
           if (((i % 3 == 0) && (i % 7 == 0)) && (i % 2 != 0)) {
               printf("%d\t",i);
           }
       }  

return 0;
}
Output:
Odd numbers from 0 to 102 divisible by either 3 and 7 : 21   63  

(e) Write a program that prints all of the even numbers from 30 to 102 divisible by either 3 or 7
Program:

#include <stdio.h>
int main()
{
int i = 0;
       printf("\nEven numbers from 30 to 102 divisible by either 3 or 7 : ");
       for (i = 30; i <= 102; i++) {
           if (((i % 3 == 0) || (i % 7 == 0)) && (i % 2 == 0)) {
               printf("%d\t",i);
           }
       }  

return 0;
}
Output:
Even numbers from 30 to 102 divisible by either 3 or 7 : 30   36   42   48   54   56   60   66   70   72   78   84   90   96   98   102  

(f) Write a program that prints all of the odd numbers from 28 to 102 divisible by either 3 or 7
Program:

#include <stdio.h>
int main()
{
int i = 0;
       printf("\nOdd numbers from 28 to 102 divisible by either 3 or 7 : ");
       for (i = 28; i <= 102; i++) {
           if (((i % 3 == 0) || (i % 7 == 0)) && (i % 2 != 0)) {
               printf("%d\t",i);
           }
       }

return 0;
}
Output:
Odd numbers from 28 to 102 divisible by either 3 or 7 : 33   35   39   45   49   51   57   63   69   75   77   81   87   91   93   99  

(g) Write a program that prints all of the odd numbers between 30 to 102 divisible by both 3
Program:

#include <stdio.h>
int main()
{
int i = 0;
       printf("\nOdd numbers from 30 to 102 divisible by either 3 and 7 : ");
       for (i = 30; i <= 102; i++) {
           if (((i % 3 == 0) && (i % 7 == 0)) && (i % 2 != 0)) {
               printf("%d\t",i);
           }
       }
return 0;
}
Output:
Odd numbers from 30 to 102 divisible by either 3 and 7 : 63  

Explanation:

Here I have used the "% (modulus)" operator to check whether number is divisible by 3 or 7 and if gives us the remainder after dividing
Example:
21%3 --> 0 it means 21 is divisible by 3

same % operator is used depending on the required result in each program.

Add a comment
Know the answer?
Add Answer to:
8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that prints all the 3 digit numbers that are divisible by 17

    Write a program that prints all the 3 digit numbers that are divisible by 17

  • Write a C program that prints the numbers from 1 to 100, but substitutes the word...

    Write a C program that prints the numbers from 1 to 100, but substitutes the word “fizz” if the number is evenly divisble by 3, and “buzz” if the number is divisible by 5, and if divisible by both prints “fizz buzz” like this: 1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizz buzz 16 17 fizz 19 buzz ... and so on

  • Question 1: Write a python program that finds all numbers divisible by 7 but not multiple...

    Question 1: Write a python program that finds all numbers divisible by 7 but not multiple of 5. The range of number for searching is between 2000 and 3200 (both included). Output should be printed in a comma-separated sequence on a single line .

  • Write a program with loops that compute a.The sum of all even numbers between 2 and...

    Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120

  • Q) How many seven digit numbers are divisible by 7? Write a function that prints a...

    Q) How many seven digit numbers are divisible by 7? Write a function that prints a list with all seven digit number divisible by 7 Q) Write a function called removeMin() that removes the minimum value from a list. You cannot use the min function nor the remove method. If a list has more than one copy of the minimum value, remove only the first occurence.

  • Use Python3 Write a program that prints the numbers from 1 up to 105 (inclusive), one...

    Use Python3 Write a program that prints the numbers from 1 up to 105 (inclusive), one per line. However, there are three special cases where instead of printing the number, you print a message instead: 1. If the number you would print is divisible by 3, print the message: The dog of wisdom knows all about this number. 2. If the number you would print is divisible by 7, print the message: Hold on I have a meme for this....

  • Write a while loop that prints all positive numbers that are divisible by 10 and less...

    Write a while loop that prints all positive numbers that are divisible by 10 and less than a given number n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. import java.util.Scanner; public class PositiveLess {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.print("n: ");        int n = in.nextInt();        ...        while (...)        {           ...

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out...

    Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out the sum of the two numbers in hexadecimal. (As noted in class, first do this without using a file and by reading using the cin > > command) From Wikipedia: "In mathematics and computer science, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0-9 to...

  • write program above in C only Write a program to find statistics on some random numbers....

    write program above in C only Write a program to find statistics on some random numbers. Seed the random number generator with time. In a for loop generate 12 random numbers between the values of 2 and 20. Print the numbers. As the numbers are generated, find the following: the number of even numbers (those evenly divisible by 2) e the sum of the even numbers the product of the even numbers the maximum value of all the numbers e

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT