File Operations in C language-print the prime number within 1000 to the file
// File Operations
/*
========================================================== ============================
Question: print to the dashboard number. txt.
========================================================== ============================
*/
# Include
Void main ()
{
FILE * fp;
Int n, I, k, m = 0;
Fp = fopen (D: \ Prime numbers. txt, w );
If (fp = NULL)
Printf (can not open! );
Else
{
For (n = 2; n <1000; n ++)
{
K = int (n/2 );
For (I = 2; I <= k; I ++)
If (n % I = 0)
Break;
If (I> k)
{
Printf (% 5d, n );
M ++;
Fprintf (fp, % 4d, n );
If (m % 10 = 0)
{
Fprintf (fp ,);
Printf ();
}
}
}
}
Fclose (fp );
Printf ();
}
/*
========================================================== ============================
Comment: for basic file operations, first define the pointer * fp to the file to point to the target
File, w indicates writable. Then write the prime number program and return to the basic algorithm!
========================================================== ============================
*/