Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAM NEED same output 1 - WAP to check whether a given number is prime or not using function. Pre-requisites: Loops Arithmatic operators Conditional

C PROGRAM NEED same output

1 - WAP to check whether a given number is prime or not using function. Pre-requisites:

Loops

Arithmatic operators

Conditional constructs

Functions

Objective: > To understand the concept of

Loops (Exit points of loops)

Conditional constructs

Functions and return value

Requirements:

Read a number from user.

Pass the number to the function is_prime().

Check the number is prime or not in the function.

Return 1 if the number is prime, or return 0 if the number is not prime.

Print the output in the main function based on the return value.

Sample Execution: Test case 1: prime_or_not Enter a number: 2 2 is a prime number Test case 2: prime_or_not Enter a number: 4 4 is not a prime number Test case 3: /prime_or_not Enter a number: 101 101 is a prime number Test case 4: prime_or_not Enter a number: 47 47 is a prime number Test case 5: user@emertxe]./prime_or_not Enter a number: -2 Invalid input Test case 6: user@emertxe]./prime_or_not Enter a number: 25 25 is not a prime number Test case 7: user@emertxe]./prime_or_not Enter a number: 2089

2089 is a prime number

Requested files

#include

int is_prime(int);

int main() { return 0; }

//

2 - WAP to generate the prime series upto the given limit using functions

Pre-requisites:

Loops

Arithmatic operators

Conditional constructs

Functions

Objective: To understand the concept of

Loops (Exit points of loops)

Conditional constructs

Functions & its use, return value

Requirements:

Read a number from user.

Create a function is_prime(), which will check the number is prime or not.

Create a function generate_prime(), which will reuse the function is_prime() to create prime series.

Function Prototypes: - int prime(int num); - void generate_prime(int limit); Sample Execution: Test case 1: prime_or_not Enter a number: 2 2 Test case 2: prime_or_not Enter a number: 4 2 3 Test case 3: prime_or_not Enter a number: 20 2 3 5 7 11 13 17 19 Test case 5: prime_or_not Enter a number: -2 Invalid input Test case 6: prime_or_not Enter a number: 1

Invalid input

Requested files

prime_series.c

#include

int is_prime(int);

void generate_prime(int);

int main() { int limit; printf("Enter the limit: "); scanf("%d", &limit); if (limit > 1) { generate_prime(limit); } else { printf("Invalid input "); } return 0; }

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

How is a CFD contract terminated?

Answered: 1 week ago

Question

Is there a clear hierarchy of points in my outline?

Answered: 1 week ago