codes Flashcards
1
Q
primes in array
A
include <iostream></iostream>
#include <math.h></math.h>
int main() {
int arr[] = {1,2,3,4,5,6,7,8,9};
int i = 0;
int j = 2;
for(i=0;i<(sizeof(arr)/sizeof(arr[i])); i++){
bool flag = true;
for(j=2;j<=sqrt(arr[i]);j++){
if(arr[i]%j==0){
flag = false;
break;
}
}
if(flag==true && arr[i]>1){
std::cout«arr[i] «_space;” “ ;
}
}
}
2
Q
A