Topic requirements: Given a range of numbers, the output satisfies these conditions:
1. Can be divisible by 3;
2. Contains the number 5,
The number of occurrences of the number and number of digits in these numbers is output and output by placing the satisfied numbers in a specific array. 5
Think of a little sad, originally very simple problem, the test when the program wrote the wrong line, the result has become a dead cycle, and finally did not find out the wrong, down later only remembered. Must be long after dessert.
Code:
#include<stdio.h>
intFlagintX0,intX1,intB[],int*P);
intMain () {
intI,intnumber,fivenumber;//number of numbers,5the number
intb[301];//bStore the number of satisfied
FILE *FP;
Fp=fopen ("Myfile.out","W");
Intnumber=flag ( $, -, B,&fivenumber);
for(i=0; i<intnumber;i++) {
printf"%d", B[i]);//Specific output requirements forget, that's roughly the case.
fprintf (FP,"%d", B[i]);
}printf ("Number of 5:%d\ n", Fivenumber);
fprintf (FP,"%d\ n", Fivenumber);
fprintf (FP," test number ");
Fclose (FP);
return0;
}
intFlagintX0,intX1,intB[],int*P) {
intIntnumber,wei,flg,i,j,temp;
intnumber=*p=flg=0;
for(i=x0;i<=x1;i++) {
flg=0;
if(i%3==0){
Temp=i;
wei=temp%Ten;
temp=temp/Ten;//it was writtenI/10, so it became a dead loop.
for(j=0;wei>0; j + +) {
if(wei==5){
flg=1;
(*p) + +;
}
wei=temp%Ten;
temp=temp/Ten;//Same as above
}
}
if(flg==1) {//This code does not write the wrong layer, to write in the traversal of the number of this layer
B[intnumber]=i;
intnumber++;
}
}
returnIntnumber;
}
2018.3 Jiangsu Province Computer Grade Examination C language programming question answer