Computer Science, asked by danishjoshi111, 1 year ago

Make an algorithm and a program to get an integer from the user as an input and classify it as prime number or non-prime number .(language : c/c++)

Answers

Answered by 140536
1
i used java ===> i have NOT  studied CPP 
====> in java <====

............................
import java.util.*;
{
public static void main(String arg[])
{
Scanner sc = new Scanner (System.in);
int n,i,c=0;
System.out.println("Enter a Number");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
n=n%i;
c=c+1;
System.out.println("NOT!");
}}
For eg;if the number given is 2
Output:
Prime Number
if the number given is 8
Output:
NOT!
......................................
Answered by ruchisr123
0
n=sc.nextInt();
for(i=1;i<=n;i++)
{
n=n%i;
c=c+1;
System.out.println("NOT!");
}}
For eg;if the number given is 2
Output:
Prime Number
if the number given is 8
Output:
NOT!

ruchisr123: mark as best ans
Similar questions