First, the topic requirements
The known data file In.dat has 300 four-digit numbers, and calls the Readdat () function to store these numbers in array A, write the function jsvalue (), the function is: to find out all these four-digit number is the number of prime numbers CNT, and then all the four-digit number satisfies this condition in the array B, Then the array b is arranged in order from small to large, and the last write function Wirtedat () outputs the number in the B to the Out.dat file.
Ii. contents of In.dat file
7704,9774,3213,5845,7703,2902,1925,2584,7429,66463793,8640,4364,3032,9190,2498,6394,3796,2434,67915552,9052,9159,8245,7965,1071,8157,6526,2164,67674853,1174,4564,5427,7279,9832,3640,7897,3211,47886556,4781,2168,6014,7795,6536,9461,4287,8029,83032609,8795,8386,3911,8130,7268,1906,7345,3678,58238074,6963,7874,6066,4509,8976,1740,2026,7047,47309538,2193,8473,6729,4207,5095,4623,4933,6226,80981277,5480,1906,4109,9047,1986,5882,8444,1029,65152612,7297,6934,8495,7731,1625,1305,7953,7385,36207206,4549,5736,3131,6875,6917,6087,4640,5314,86466077,5677,7345,4143,1513,8101,2038,9879,3946,66437763,6108,4788,9055,8186,5416,5699,6733,5416,23202430,4772,9962,9676,1319,7767,7369,1411,3663,28762245,4810,5400,6045,1504,4178,7264,2763,7050,14908790,4014,9280,7105,7113,3600,8221,8203,6127,73131850,5983,9689,4102,1036,6375,5064,7188,9887,98006871,4856,2432,9562,3426,9013,5104,4724,4785,99535939,6668,8700,4730,9737,4055,6544,9763,1034,28558078,5111,4817,4593,9876,1189,2507,1197,1782,43477961,8612,9699,6108,4221,2489,8895,3672,8226,87246302,7624,7506,8568,4013,2785,3528,6712,1155,31501388,5803,6328,6841,5825,7802,2022,6290,1775,36529699,6573,8082,9016,4369,4002,3205,2688,8414,75722830,1231,3888,5137,5555,8976,2543,6542,8986,59215346,1368,2566,3304,4089,3880,1244,6650,6523,61231243,7488,5262,9992,3115,9270,6989,1595,1283,26454075,9471,7983,9093,7642,8847,5686,4168,8550,89415188,2290,3219,2853,6978,9053,5843,7153,6382,62893022,5591,9981,7296,2421,7328,9575,7586,1190,8504
View CodeThird, the program code
#include <stdio.h>inta[ -], b[ -], cnt=0; voidReaddat () {FILE*FP; inti; FP= fopen ("In.dat","R"); for(i =0; I < -; i++) {fscanf (FP),"%d,", &A[i]); } fclose (FP); }voidWritedat () {FILE*FP; inti; FP= fopen ("Out.dat","W"); fprintf (FP,"%d\n", CNT); for(i =0; I < CNT; i++) {fprintf (FP),"%d\n", B[i]); } fclose (FP); } intIsP (intm) {inti; for(i =2; I < m; i++) if(m% i = =0) return 0; return 1; }voidJsvalue () {inti,j; inttemp; for(i=0;i< -; i++) { if(IsP (A[i])) {b[cnt++]=A[i]; } } //method One: Bubble sort for(i=0; i<cnt;i++) { for(j=0; j<cnt-i-1; j + +) { if(b[j]>b[j+1]) {temp=B[j]; B[J]=b[j+1]; B[j+1]=temp; } } } //Method Two: /*For (i = 0; i < cnt, i++) {for (j = i + 1; j < CNT; J + +) {if (B[i] > B[j]) {temp = B[j]; B[J] = B[i]; B[i] = temp; } } }*/}voidMain () {inti; Readdat (); Jsvalue (); Writedat (); printf ("cnt=%d\n", CNT); for(i =0; I < CNT; i++) {printf ("b[%d]=%d\n", I, b[i]); }}
View CodeIv. Results of program operation
C language daily practice--the fourth question