2018.3 江蘇省電腦等級考試 C語言 編程題答案

來源:互聯網
上載者:User

標籤:AC   style   江蘇省   代碼   printf   簡單的   答案   margin   5.0   


題目要求:給定一個數字範圍,輸出滿足這些條件:

1.能被3整除;

2.包含數字5,

將滿足的數字放在特定的數組裡輸出、輸出這些數裡5出現的個數、數位個數。

想起來有點傷心,本來很簡單的題,考試的時候程式寫錯一行,結果成了死迴圈,最後還沒找出來錯,下來以後才想起來。以後必須長點心。

代碼:

#include<stdio.h>
int flag(int x0,int x1,int b[],int *p);
int main(){
int i,intnumber,fivenumber;//數位個數、5的個數
int b[301];//b存放滿足的數字
FILE *fp;
fp=fopen("myfile.out","w");

intnumber=flag(200,300,b,&fivenumber);
for(i=0;i<intnumber;i++){
printf("%d ",b[i]);//具體的輸出要求忘了,大致是這樣
fprintf(fp,"%d ",b[i]);
}
printf("5的個數:%d\n",fivenumber);
fprintf(fp,"%d\n",fivenumber);
fprintf(fp,"考號");
fclose(fp);
return 0;
}
int flag(int x0,int x1,int b[],int *p){
int intnumber,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%10;
temp=temp/10;//當時寫成了i/10,所以成了死迴圈
for(j=0;wei>0;j++){
if(wei==5){
flg=1;
(*p)++;
}
wei=temp%10;
temp=temp/10;//同上面一樣
}
}
if(flg==1) {//這段代碼不要寫錯層,要寫在遍曆數位這層
b[intnumber]=i;
intnumber++;
}
}
return intnumber;
}

 

2018.3 江蘇省電腦等級考試 C語言 編程題答案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.