找出个位数为6且能被3整除的五位数

根据:能被3整除的数其各位的总和,也能被3整除的原则,加之个位6能被3整除,所以就只用考虑高4位,在这里就可以采用如下方法获得最终结果

 1 /*==================================
 2 Copyright (C) 2014 All rights reserved.
 3 FileName:3.c
 4 author:donald
 5 date:2014/08/16/ 23:35:55
 6 ===================================*/
 7 #include <stdio.h>
 8 #include <stdlib.h>
 9 #include <string.h>
10 
11 int main(int argc, const char *argv[])
12 {
13     int index,cnt ;
14     for(index = 1000;index < 9999;index ++){
15         if(index % 3 == 0){
16             cnt ++;
17             printf("%8d",index*10 + 6) ;
18         }
19     }
20     printf("\nresult is %d \n",cnt);
21     return 0;
22 }

 

posted @ 2014-08-17 00:06  donald_su  阅读(758)  评论(1编辑  收藏  举报