Question

In: Electrical Engineering

Use "do...while" loops to write a program that finds all prime numbers less than a specified...

Use "do...while" loops to write a program that finds all prime numbers less than a specified value.

Solutions

Expert Solution

%Program to find follows


#include <stdio.h>
#include <math.h>

int main(void)
{ printf("Please enter a maximum value...\n"); int max;
    scanf("%d", &max);

    int current = 4;
    int checker = 2;
    do{
        if(checker > sqrt((double)current))
        {
            checker = 2;
            printf("%d is prime\n",current);
            current++;
        }
        else if(current % checker == 0)
        {
            checker = 2;
            printf("%d is NOT prime\n",current);
            current++;
        }
        else
            checker++;
    }while(current < max);
}

Output:

I have entered max value is 20.


Related Solutions

In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Write a program that prints out all numbers, less than or equal to 10,000,000, that are...
Write a program that prints out all numbers, less than or equal to 10,000,000, that are evenly divisible by all numbers between 5 and 15 (inclusive). Do not use any libraries besides stdio.h. Need it in 10 minutes, please.
Write a c++ program that prints the count of all prime numbers between A and B...
Write a c++ program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = Any 5 digit unique number B = A + 1000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
Write a program that prints the count of all prime numbers between A and B (inclusive),...
Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7,...
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers....
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat, otherwise, it should terminate. Use Continue branching statement Write a program that reads an integer and display all the positive ODD numbers from 0 to n (integer entered by the user). Use CONTINUE...
Write a program that generates all prime numbers between 2 and 1000, using the Sieve of...
Write a program that generates all prime numbers between 2 and 1000, using the Sieve of Eratosthenes method. You can find many articles that describe the method for finding primes in this manner on the Internet. Display all the prime values. This program should be in assembly language.
Question : Write a C++ program to find all prime numbers between 10 to 100 by...
Question : Write a C++ program to find all prime numbers between 10 to 100 by using while loop. Hint: a prime number is a number that is divisible by 1 and itself. For example 3, 5, 7, 11, 13 are prime numbers because they are only divisible by 1 and themselves.
(Use the GenericStack class) Write a program that displays the first 100 prime numbers in descending...
(Use the GenericStack class) Write a program that displays the first 100 prime numbers in descending order. Use a stack to store the prime numbers.
Write a program that will print the whole numbers from a user-specified minimum to a user-specified...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT