C language prime number

Functions: selecting 100 or more in all of 1000 the ones digit and the tens digit of the remainder obtained by dividing 10 by precisely one hundred prime numbers (e.g., 293). Calculates and outputs these cnt number of prime numbers and values ​​of these factors and the sum.

Please write function countValue () to achieve procedural requirements, after calling the function writeDAT () cnt and sum the output to a file bc10.out in.
#include <stdio.h>

int cnt, I;

int isPrime(int m)

{

int i;

for(i=2;i<m;i++)

if(m % i==0)return 0;

return 1;

}

void countValue()

You {i, j, bw, sw, gw;

for(i=100;i<1000;i++)

{Bw = i / 100; sw = i% 100/10; gw = i% 10;

if(isPrime(i)&&(gw+sw)%10==bw) { cnt++; sum+=i;}

}

}

void main()

{

cnt = I = 0;

countValue() ;

printf ( "number of primes =% d \ n", cnt);

printf ( "prime value satisfies the condition and =% d", sum);

writeDAT() ;

}

writeDAT()

{

FILE *fp ;

fp = fopen(“bc10.out”, “w”) ;

fprintf(fp, “%d\n%d\n”, cnt, sum) ;

fclose(fp) ;

}

Published 239 original articles · won praise 3 · Views 3165

Guess you like

Origin blog.csdn.net/it_xiangqiang/article/details/105164154