Skip to content

Instantly share code, notes, and snippets.

@nsuan
Created April 28, 2009 08:13
Show Gist options
  • Save nsuan/103022 to your computer and use it in GitHub Desktop.
Save nsuan/103022 to your computer and use it in GitHub Desktop.
//#include "iostream.h"
#include "stdio.h"
void main() {
int i, n, x;
i = 2;
while(n > 0) {
printf( "Input a number. Enter a negative number to exit: ");
scanf( "%d" , &n);
if (n < 0)
break;
x = 0;
while( i <= n) {
x = n % i;
int p;
float m = 1;
m = i/n;
p = m * 100;
printf("\rTesting number: %d \t \t", i);
printf(" %d percent done.", p);
if ((x == 0) && (n == i)) {
printf("\n%d is prime.\n", n);
break;
}
if ((x == 0) && (n != i)) {
printf("\n%d is not prime. \n", n);
break;
}
i++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment