Who could write how to find a prime number in dynamic array?



Who could write how to find a prime number in dynamic array?..

Answer / basavaraj

class Demo{
static boolean prime(int n){
int c=0;
for(int i=0;i<n;i++){
if(n%i==0){
c++;
}
}
if(c==2){
return true;
}else{
return false;
}

public static void main(String[] args){
int[] arr={2,5,7,6,8,11,14,13,50};
for(int i=0;i<arr.length;i++){
if(prime(arr[i]){
System.out.println(arr[i]+" ");
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }

1 Answers  


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


can u give me the c codings for converting a string into the hexa decimal form......

1 Answers  


main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); } a. Runtime error. b. 0, 0 c. Compile error d. the first two values entered by the user

2 Answers   HCL,


main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }

1 Answers  






# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }

1 Answers  


#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above

3 Answers   HCL,


main() { extern int i; i=20; printf("%d",i); }

1 Answers   Value Labs,


write a c-program to display the time using FOR loop

3 Answers   HCL,


int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

2 Answers  


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

2 Answers   Wipro,


Is it possible to print a name without using commas, double quotes,semi-colons?

7 Answers  


Categories