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 |
Design an implement of the inputs functions for event mode
Give a oneline C expression to test whether a number is a power of 2?
25 Answers EA Electronic Arts, Google, Motorola,
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?
Write a program to print a square of size 5 by using the character S.
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above
Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.
1 Answers Samar State University,