(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.
8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...
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 “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
Write a complete program that prints numbers from 1 to 50, but if numbers that are multiples of 5, print HiFive, else if numbers that are divisible by 2, print HiTwo, and else if numbers that are divisible by 3 or 7, print HiThreeorSeven *Please in python*
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 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
using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: must use loops and numbers to do this 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers
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 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 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 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...