Skip to content

Instantly share code, notes, and snippets.

@nguyenvanquan7826
Last active February 28, 2020 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nguyenvanquan7826/c3e2cdc7cce7c4e2bfd559f2467c6a6a to your computer and use it in GitHub Desktop.
Save nguyenvanquan7826/c3e2cdc7cce7c4e2bfd559f2467c6a6a to your computer and use it in GitHub Desktop.
ChamCode.net Code
#include <stdio.h>
int check(int n) {
if(n < 2) return 0; // n not is prime
for(int i = 2; i < n; i++) {
if(n % i == 0) return 0; // n not is prime
}
return 1; // n is prime
}
int main() {
int n;
scanf("%d", &n);
int count = 0, s = 0;
for (int i = 2; i <= n; i++) {
if( check(i) ) {
count++;
s += i;
}
}
printf("%.3f", (float)s / count);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment