Last active
February 28, 2020 08:58
-
-
Save nguyenvanquan7826/c3e2cdc7cce7c4e2bfd559f2467c6a6a to your computer and use it in GitHub Desktop.
ChamCode.net Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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