Computer Science, asked by geetharudregowda53, 7 months ago

17. Write a program to input an integer and check whether it is a prime number or not​

Answers

Answered by sreeraj01
2

Explanation:

#include <stdio.h>

int main() {

int n, i, flag = 0;

printf("Enter a positive integer: ");

scanf("%d", &n);

for (i = 2; i <= n / 2; ++i) {

// condition for non-prime

if (n % i == 0) {

flag = 1;

break;

}

}

if (n == 1) {

printf("1 is neither prime nor composite.");

}

else {

if (flag == 0)

printf("%d is a prime number.", n);

else

printf("%d is not a prime number.", n);

}

return 0;

}

Answered by CopyThat
3

Explanation:

import java.util.*;

class Brainly

{

static void main()

{

int i,j,n,s=0,c,p=0,l=0;

Scanner sc=new Scanner(System.in);

System.out.println(“Enter 10 integers:”);

for(i=1;i<=10;i++)

{

n=sc.nextInt();

c=0;

for(j=1;j<=n;j++)

{

if(n%j==0)

c++;

}

if(c==2)

{

p++;

if(p==1)

l=n;

if (n>l)

l=n;

}

}

if(p>0)

System.out.println(“Largest prime numbers=”+l);

else

System.out.println(“No prime no.s present”);

}

}

Similar questions