2018.3 Jiangsu Province Computer Grade Examination C language programming question answer

Source: Internet
Author: User


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

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.