matthewmpp@annrogers:~/Programming/C.progs/Personal$ cat prime4.c
/*
* File: main.c
* Author: matthewmpp
*
* Created on November 7, 2010, 2:16 PM
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/*
prime numbers.
version4
should tell whether a number is prime or not prime.
by using other prime numbers.
*/
int input_func ()
{
char line[100];
int n_input;
while (1) {
printf("Please enter a whole number.\n");
fgets(line, sizeof (line), stdin);
sscanf(line, "%d", &n_input);
if (n_input >= 0)
break;
return (n_input);
}
} …Run Code Online (Sandbox Code Playgroud) 在这段代码中:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main (int argc, char ** argv) {
uint64_t bignum = 600851475143;
int is_prime = 0;
uint64_t result = 0;
uint64_t i = 0;
uint64_t j = 0;
for (i = 0; i < bignum; i++) {
if (bignum % i == 0) {
is_prime = 1;
for (j = 0; j < i; j++) {
if (i % j == 0) {
is_prime = 0;
break;
}
}
if (is_prime) {
result …Run Code Online (Sandbox Code Playgroud) c ×2