Create a C PROGRAM that asks for an integer n and lists all prime numbers from 1 to n. Create a recursive function that determines whether an integer is prime or not. Next ask for an integer n, then loop through all the integers from 1 to n. Check each integer if it is prime by using the function earlier then print the integer if it is prime. Sample output: Enter a positive number: 5 The prime numbers from 1 to 5 are: 2 3 5 Enter a positive number: 15 The prime numbers from 1 to 15 are: 2 3 5 7 11 13 Enter a positive number: 100 The prime numbers from 1 to 100 are: 2 3 5 7 11 13 17 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

C PROGRAM

Create a C PROGRAM that asks for an integer n and lists all prime numbers from 1 to n.
Create a recursive function that determines whether an integer is prime or not. Next ask for an
integer n, then loop through all the integers from 1 to n. Check each integer if it is prime by
using the function earlier then print the integer if it is prime.
Sample output:
a positive number: 5
The prime numbers from 1 to 5 are: 2 3 5
Enter
Enter a positive number: 15
The prime numbers from 1 to 15 are: 2 3 5 7 11 13
Enter a positive number: 100
The prime numbers from 1 to 100 are: 2 3 5 7 11 13 17 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89 97
Transcribed Image Text:Create a C PROGRAM that asks for an integer n and lists all prime numbers from 1 to n. Create a recursive function that determines whether an integer is prime or not. Next ask for an integer n, then loop through all the integers from 1 to n. Check each integer if it is prime by using the function earlier then print the integer if it is prime. Sample output: a positive number: 5 The prime numbers from 1 to 5 are: 2 3 5 Enter Enter a positive number: 15 The prime numbers from 1 to 15 are: 2 3 5 7 11 13 Enter a positive number: 100 The prime numbers from 1 to 100 are: 2 3 5 7 11 13 17 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr