Cod sursa(job #1143321)

Utilizator yo_andrei_2003Murica Andrei yo_andrei_2003 Data 15 martie 2014 14:50:15
Problema Ciurul lui Eratosthenes Scor 20
Compilator c Status done
Runda Arhiva educationala Marime 0.48 kb
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, p, i, s, nr=0;
    FILE *fin, *fout;
    fin=fopen("ciur.in" ,"r");
    fout=fopen("ciur.out" ,"w");
    fscanf(fin, "%d" ,&n);
    i=2;
    while(i<n) {
        p=2;
        s=0;
        while (p<i) {
            if (i%p==0) {
                s=1;
            }
            p++;
        }
        i++;
        if(s==0) {
            nr++;
        }
    }
    fprintf(fout, "%d" ,nr);
    return 0;
}