/////PRIME NUMBER////
void setup() {
size(500, 200);
background(0);
int n=15;//number
int count=2;
int sum=0;
int divNo=2;
int posx=0;
while (count<=n) {
if (PrNum_result(count)) {
sum=sum+count;
textSize(20);
text(count, 30+posx, 100);
posx=posx+30;
}
count+=1;
}
text("Sum is = "+sum, 30, 150);
}
boolean PrNum_result(int count) {
int divNo=2;
boolean pr=true; //first one =2
while (divNo<count) {
if (count%divNo==0) {
pr=false;
break;
}
pr=true;
divNo+=1;
}
return pr;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น