File Operations in C language-print the prime number within 1000 to the file

Source: Internet
Author: User

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!
========================================================== ============================

*/

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.