C语言要求输出从1到9999中能被7整除,而且至少有一位数字是5的所有数字,输出格式一行一个

必须一行一个

#include <stdio.h>

int main(void) 
{
int i,t;
for(i=7;i<9999;i+=7)
{
for(t=i;t;t/=10)
{
if(t%10==5)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}

追问

为什么只能输出5005以后的数字,我要从35开始的

温馨提示:内容为网友见解,仅供参考
第1个回答  2012-11-30
一、35
35+70
35+70*2
35+70*3
35+70*4
35 +70*5
35+70*6 等等----按这个规律找下去就行,但除50到60之间的和500到600之间
的和 5000到6000之间的
二、56 只属于50到60之间的
三、504
504+7
504+7*2
504+7*3
504+7*4 等等----按这个规律找下去就行,但只属于500到600之间的
四、5001
5001+7
5001+7*2
5001+7*3
5001+7*4 等等----按这个规律找下去就行,但只属于5000到6000之间的
第2个回答  2012-12-05
在GCC环境下运行一下程序:
#include<stdio.h>
void main()
{
int a,b,n;
for (n=0;n<=9999;n++)
{
if (n%7==0)
{
a=n;
while(a!=0)
{
b=a/10;
b=a-b*10;
a=a/10;
if (b==5)
{printf ("%d\n",n);break;}
}
}
}
}
第3个回答  2015-10-24
#include<stdio.h>
void main()
{
int a,b,c,d,s,f;
printf("35\n");
for(s=100;s<=999;s++)
{
a=s/100;
b=s/10%10;
c=s%10;
if((s%7==0)&&(a==5||b==5||c==5))
printf("%d\n",s);
}
for(f=1000;f<=9999;f++)
{
a=f/100%10;
b=f/10%10;
c=f%10;
d=f/1000;
if(((f%7==0)&&(a==5||b==5||c==5||d==5)))
printf("%d\n",f);
}
}追问

56呢,56也是为什么程序没有,而且只能输出5005以后的数字啊

追答

额。这是我的失误,少写了个56。另外你把\n换成空格就能看到5000以前的了。

本回答被提问者采纳
第4个回答  2012-11-30
35,56,105,154,175,245,252,259,315,350,357,385,455,504,511,518,525,532,539,546,553,560,567,574,581,588,595,651,658,665,735,756,805,854,875,945,952,959,1015,1050,1057,1085,1155,1225,1253,1295,1351,1358,1365,1435,1456,1505,1512,1519,1526,1533,1540,1547,1554,1561,1568,1575,1582,1589,1596,1645,1652,1659,1715,1750,1757,1785,1855,1925,1953,1995,2051,2058,2065,2135,2156,2205,2254,2275,2345,2352,2359,2415,2450,2457,2485,2506,2513,2520,2527,2534,2541,2548,2555,2562,2569,2576,2583,2590,2597,2625,2653,2695,2751,2758,2765,2835,2856,2905,2954,2975,3045,3052,3059,3115,3150,3157,3185,3255,3325,3353,3395,3451,3458,3465,3500,3507,3514,3521,3528,3535,3542,3549,3556,3563,3570,3577,3584,3591,3598,3605,3654,3675,3745,3752,3759,3815,3850,3857,3885,3955,4025,4053,4095,4151,4158,4165,4235,4256,4305,4354,4375,4445,4452,4459,4501,4508,4515,4522,4529,4536,4543,4550,4557,4564,4571,4578,4585,4592,4599,4655,4725,4753,4795,4851,4858,4865,4935,4956,5005,5012,5019,5026,5033,5040,5047,5054,5061,5068,5075,5082,5089,5096,5103,5110,5117,5124,5131,5138,5145,5152,5159,5166,5173,5180,5187,5194,5201,5208,5215,5222,5229,5236,5243,5250,5257,5264,5271,5278,5285,5292,5299,5306,5313,5320,5327,5334,5341,5348,5355,5362,5369,5376,5383,5390,5397,5404,5411,5418,5425,5432,5439,5446,5453,5460,5467,5474,5481,5488,5495,5502,5509,5516,5523,5530,5537,5544,5551,5558,5565,5572,5579,5586,5593,5600,5607,5614,5621,5628,5635,5642,5649,5656,5663,5670,5677,5684,5691,5698,5705,5712,5719,5726,5733,5740,5747,5754,5761,5768,5775,5782,5789,5796,5803,5810,5817,5824,5831,5838,5845,5852,5859,5866,5873,5880,5887,5894,5901,5908,5915,5922,5929,5936,5943,5950,5957,5964,5971,5978,5985,5992,5999,6055,6125,6153,6195,6251,6258,6265,6335,6356,6405,6454,6475,6503,6510,6517,6524,6531,6538,6545,6552,6559,6566,6573,6580,6587,6594,6615,6650,6657,6685,6755,6825,6853,6895,6951,6958,6965,7035,7056,7105,7154,7175,7245,7252,7259,7315,7350,7357,7385,7455,7504,7511,7518,7525,7532,7539,7546,7553,7560,7567,7574,7581,7588,7595,7651,7658,7665,7735,7756,7805,7854,7875,7945,7952,7959,8015,8050,8057,8085,8155,8225,8253,8295,8351,8358,8365,8435,8456,8505,8512,8519,8526,8533,8540,8547,8554,8561,8568,8575,8582,8589,8596,8645,8652,8659,8715,8750,8757,8785,8855,8925,8953,8995,9051,9058,9065,9135,9156,9205,9254,9275,9345,9352,9359,9415,9450,9457,9485,9506,9513,9520,9527,9534,9541,9548,9555,9562,9569,9576,9583,9590,9597,9625,9653,9695,9751,9758,9765,9835,9856,9905,9954,9975

C语言要求输出从1到9999中能被7整除,而且至少有一位数字是5的所有数字...
include <stdio.h>int main(void) {int i,t;for(i=7;i<9999;i+=7){for(t=i;t;t\/=10){if(t%10==5){printf("%d\\n",i);break;}}}return 0;}

...而且至少有一位数字是5的所有数字 输出格式一行一个
include <stdio.h>#include <stdlib.h>int main(void){ int a,b,c,d,e,p,n; char str[5]; for(n=1;n<=9999;n++){if(n%7==0){ sprintf(str, "%0d", n); for(a=0;a<4;a++) { if(str[a]==53){ printf("得到目标数:%s\\n",str);break;...

输出1到9999中能被7整除,而且至少有一位数字是5的所有数字。输出时一...
++count; if(count == 5) { cout<<endl; count = 0; } } } return 0;}

输出1到9999中能被7整除,而且至少有一位数字是5的所有数字
using namespace std;inline bool check(long a){ while (a){ if (a%10==5) return 1;a\/=10;} return false;} int main(){ for (long a=1;a<=9999;++a){ if (a%7==0){ if (check(a)){ printf("%d ",a);} } } system("pause");return 0;} ...

输出1到9999中能被7整除,而且至少有一位数字是5的所有数字
245,252,259,315,350,357,385,455,504,511,518,525,532,539,546,553,560,567,574,581,588,595,651,658,665,735,756,805,854,875,945,952,959,1015,1050,1057,1085,1155,1225,1253,1295,1351,1358,1365,1435,1456,1505,1512,1519,1526,1533,1540,1547,1554,1561,1568,1575,1582,...

c++ 能被5整除且至少有一位数字是5的所有整数的个数
恩,少了括号,后面的那些都要满足能被5整除,&& 和 || 优先级相同,就像+ 和 - 一样,所以你这样就要从左到右依次运算了 就成了 if (i能被5整除 且 i除以10余5)或(...)或(...)或(...)或(...)了

有多少个四位整数,从1000到9999至少有一个数字是重复的?
结果为 4464。

C语言,查从 100到 10000之间所有位上都相同的所有数,111,9999这种,最后...
include <stdio.h> int f(int n){\/*数字n位相同数字的整数,返回总的个数*\/ int i,j,x=0;for (i=1;i<=9;i++){for (j=1;j<=n;j++) printf("%d",i);printf("\\n");x++;} return x;} void main(){\/*主程序*\/ int n;n=f(2)+f(3)+f(4);printf("总共输出 %d ...

C语言课程设计报告要求
首先对万年历年、月、日进行编写,编写程序先定义每月的天数为28天,如月份为1、3、5、7、8、10、12就定义天数为31天反之如果月份为4、6、9、11就输出天数为30天,由上可见2月份为28天但是如果为闰年就有29天就要定义另一个函数#define Year(x) (x%4==0&&x%100!=0||x%400==0) ? 1:0当为闰年时...

有没c++的题集及答案
求[100,300]之间所有能被其因子数目整除的数之和。7、已知24有8个因子(即:1,2,3,4,6,8,12,24),而24正好被8整除。求[1,100]之间第二大能被其因子数目整除的数。五位数.求五位数各数字的平方和为100的最大的五位数。8、设有6个十进制数字a,b,c,d,f,e,求满足abcdf×e=fdcba条件的五位数abc...

相似回答