Is it possible (or practical) to do this without using exit() or goto? And do I need the default case, since there is only one case I am worried about? I have a version using if(), would it be more efficient to use that instead? Do I need the break after exit() since the program will have ended anyway?
Thanks.Code:#include<iostream> using namespace std; int main() { int n; int i; printf("Please enter an integer\n"); scanf("%d",&n); for(i=2;i<n;i++) { switch(n%i) { case 0: printf("%d is not a prime\n",n); exit(0); break; default: break; } } printf("%d is a prime\n",n); return 0; }