write a program to accept any 20 numbers and display only those numbers which are composite.
hint: a numbers said to be composite if it has more than two factors
Answers
Answer:
JAVA PROGRAM
import java.util.*;
public class Composite
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int i, j, k, factor;
int n[]=new int[20];
for(i=0;i<20;i++)
{
System.out.print("Enter the number: ");
n[i]=in.nextInt();
}
System.out.println("The composite nos are: \n");
for(i=0;i<20;i++)
{
k=n[i];
{
factor=0;
for(j=1;j<k;j++)
{
if(k%j==0)
factor++;
}
}
if(factor>1)
System.out.print(n[i]+" ");
}
}
}
Explanation:
OUTPUT YOU CAN PUT ANY NUMBER.
Enter the number: 1
Enter the number: 2
Enter the number: 3
Enter the number: 4
Enter the number: 5
Enter the number: 6
Enter the number: 7
Enter the number: 8
Enter the number: 9
Enter the number: 10
Enter the number: 11
Enter the number: 12
Enter the number: 13
Enter the number: 14
Enter the number: 15
Enter the number: 16
Enter the number: 17
Enter the number: 18
Enter the number: 19
Enter the number: 20
The composite nos are:
4 6 8 9 10 12 14 15 16 18 20