Docsity

Implementing a Function to Check Prime Numbers in Turbo C, Study notes of Computer Science

Toggle sidebar
bg1
Exp no.-9
Date-6-3-21
Implement using functions to check whether the given number is prime
and display appropriate messages. (No built-in math function)
Aim:
To implement using functions to check whether the given number is prime and display
appropriate messages. (No built-in math function)
Algorithm:
Step 1: start
Step 2: get the no. n from the user and int i, m=0, f=0.
Step 3: m=n\2
Step 4: for(i=2, i<=m, i++)
Step 5: start loop if(n%i==0)
Step 6: print the non-prime no.
Step 7: if(f==0)
Step 8: print the prime no.
Step 9: stop the loop
Step 10: stop
pf3
pf4

Partial preview of the text

Download Implementing a Function to Check Prime Numbers in Turbo C and more Study notes Computer Science in PDF only on Docsity!

Exp no.- Date-6-3-

Implement using functions to check whether the given number is prime

and display appropriate messages. (No built-in math function)

Aim: To implement using functions to check whether the given number is prime and display appropriate messages. (No built-in math function) Algorithm:Step 1: start  Step 2: get the no. n from the user and int i, m=0, f=0.  Step 3: m=n
Step 4: for(i=2, i<=m, i++)  Step 5: start loop if(n%i==0)  Step 6: print the non-prime no.  Step 7: if(f==0)  Step 8: print the prime no.  Step 9: stop the loop  Step 10: stop

Flowchart: start Get the no.. n from the user and int i, m=0, f=0. m=n
for(i=2, i<=m, i++) if(f==0) (^) if(n%i==0) print the prime no. print the non-prime no. stop

Output: Result: Hence we developed a program to Implement using functions to check whether the given number is prime and display appropriate messages. (No built-in math function).