Mips program to find prime numbers in array
Answers
Answered by
1
#include <stdio.h> int main() { int array[100], minimum, size, c, location = 1; printf("Enter the number of elements in array\n"); scanf("%d",&size); printf("Enter %d integers\n", size); for ( c = 0 ; c < size ; c++ ) scanf("%d", &array[c]); minimum = array[0]; for ( c = 1 ; c < size ; c++ ) { if ( array[c] < minimum ) { minimum = array[c]; location = c+1; } } printf("Minimum element is present at location %d and it's value is %d.\n", location, minimum); return 0; }
Answered by
0
Answer:
import java.util.*;
class Prime_no
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements to be entered");
int n=sc.nextInt();
int a[]=new int[n];
int f;
System.out.println("Enter "+n+" elements");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("Prime numbers:");
for(int i=0;i<n;i++)
{
f=0;
for(int j=1;j<=a[i];j++)
{
if(a[i]%j==0)
f++;
}
if(f==2)
System.out.println(a[i]);
}
}
}
Similar questions