how to write a program to accept 10 numbers in an array and print the factors of every number of the array?
Answers
Answered by
2
Answer:
Program in Java:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[10];
System.out.println("Enter the elements of the array:");
for(int i=0;i<a.length;i++)
{
a[i]=in.nextInt();
}
for(int i=0;i<a.length;i++)
{
System.out.print("Factors of " + a[i]+":");
int j=1;
for(j=1;j<=a[i];j++)
{
if(a[i]%j==0)
System.out.print( j+" ");
}
System.out.println();
}
in.close();
}
}
Output is attached.
Attachments:
Answered by
0
Answer:
eheididjrjfuredrefjeidiid
Similar questions