Question

2. Use function to write a program that prints all prime numbers in a range of...

2. Use function to write a program that prints all prime numbers in a range of a user input numbers.

a. Draw a flow chart for the function IsaPrimenumber [5 marks]

b. Draw a flow chart for the whole scenario [10 marks]

c. Convert the flow charts to a c program. [15 marks]

In C programming language

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
int IsaPrimenumber(int n)
{
   for(int i=2;i*i<=n;i++)
   if(n%i==0)return 0;//not a prime
  
   return 1;//prime
  
}
int main()
{
   int n;
   printf("Enter a number:");
   scanf("%d",&n);
   for(int i=2;i<=n;i++)
   if(IsaPrimenumber(i)==1)//if it is prime number
   printf("%d ",i);
  
   return 0;
}

output:

Enter a number:20
2 3 5 7 11 13 17 19

Process exited normally.
Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
2. Use function to write a program that prints all prime numbers in a range of...
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
  • Prime Numbers Write a program that will determine whether a set of randomly-generated numbers are prime...

    Prime Numbers Write a program that will determine whether a set of randomly-generated numbers are prime numbers. To write your program, you will need to use the following programming features: The random library (module) A function A variable that will prompt the user to say how many random numbers the program should generate A for loop with a range function A randint function taken from the random library (module); the randint function takes two arguments – the beginning and the...

  • Your program  write a program to test whether a number is prime or not. Your program should...

    Your program  write a program to test whether a number is prime or not. Your program should ask user to input an integer and respond: "Prime" or "Not prime". Don't use any library function that tests for prime numbers. The program should continue to ask for input, till it sees a 0, when it exits. Please submit printed pseudocodeshould ask user to input an integer and respond: "Prime" or "Not prime". Don't use any library function that tests for prime numbers....

  • Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive...

    Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive integers). • Prompts the user for a starting number: say 'x' • Prompts the user for an ending number: say 'y' • Prints out the multiplication table of 'x' up to the number 'y' SPECIFIC REQUIREMENTS 1. You must use the following method to load the array: public static void loadArray(int table[][], int x, int y) 2. You must use the following method to...

  • Please use python to write the simple program. Exercise 2 - Summation Write a program to...

    Please use python to write the simple program. Exercise 2 - Summation Write a program to accept integer inputs until the user inputs a non-integer. Then, the program prints the summation of the inputted numbers. Hint: Use the function input() to get the user input. Use a variable total for calculating the summation. Need to use while loop for the repeated inputs. Use if statement with isdigit() function to check whether the user input is an integer or not. if...

  • write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to...

    write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to enter a positive integer in the range [100, 100000]. If the integer is not in the specified range the program prompts the user again. The program prints whether the integer is a prime number or not. Sample input/output nter an integer in the range [10e, 10eeee]: 39 nter an integer in the range [100, 100000]: 120453 Enter an integer in the range [10e, 10e000e]:...

  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • Write a java program to print all the prime numbers below a certain given number. A...

    Write a java program to print all the prime numbers below a certain given number. A prime number is defined as a number that can only be divided by 1 and itself. Requirements: 1. Accept the upper limit from the user as an integer. 2. You can assume the user input will be positive and smaller than INT MAX 3. Go from 1 to the number. If you happen to find a number that is prime, print it. The input...

  • Write a C program that takes a positive integer n as input and prints all the...

    Write a C program that takes a positive integer n as input and prints all the prime numbers from 1 to n. Sample Input/Output 1: Enter your n: 20 Prime number(s) from 1 to 20 : 2 3 5 7 11 13 17 19 Sample Input/Output 2: Enter your n:2Prime number(s) from 1 to 2 : 2

  • For each question, you are required to draw a flowchart diagram and a C++ program. For...

    For each question, you are required to draw a flowchart diagram and a C++ program. For flow charts you are required to use a Computer Aided Software Engineering (CASE) tool for example Dia (Download from http://diainstaller.de/). a. Write a program that prints the first 107 prime numbers. b. Write a program that determines whether a number given by the user is a leap year or not. Please write a program in c++.. Thank you and add the comments for the...

  • 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...

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