C Language File operation 01--printing of prime numbers within 1000 to file

Source: Internet
Author: User

File operations
/*
==========================================================
Title: Print the prime number within 1000 to the D-disk "prime number. txt".
==========================================================
*/
#include <stdio.h>
void Main ()
{
FILE *FP;
int n,i,k,m=0;
Fp=fopen ("d:\\ prime number. txt", "w");
if (fp==null)
printf ("Can not open!\n");
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, "\ n");
printf ("\ n");
}
}
}
}
Fclose (FP);
printf ("\ n");

}
/*
==========================================================
Comment: File operation basic problem, first define pointer to the file *FP, make it point to the target
File, W indicates writable. Then write the prime number program, and back to the basic algorithm!
==========================================================

*/



Copyright Notice: Bo Main article can be reproduced non-commercial, but please be sure to indicate the source, because the level is limited, inevitably error, in this disclaimer.

C language File operations 01--printing of prime numbers to files within 1000

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.