/*****************************************
挑选出num以内的所有与7有关的正整型,
例如:7,17,27,75,76,774,1007 ……
*****************************************/
#include <stdio.h>
void main()
{
long int num,Count = 0,same = 0;
long int SelectNum = 7 ;
long int stradd[10000];
long int strmut[10000];
long int i = 0, j = 0, ii = 0, jj = 0;
// int k;
int ge,shi,bai,qian,wan;
scanf("%d",&num);
if(num > 30000)
exit();
else
{
if(num < 7)
{
Count = 0;
printf("%d",Count);
return;
}
for(SelectNum = 7; SelectNum <= num; SelectNum ++)
{
wan = SelectNum / 10000;
qian = SelectNum % 10000 / 1000 ;
bai = SelectNum % 1000 / 100 ;
shi = SelectNum % 100 / 10;
ge = SelectNum % 10 ;
if((wan == 7) || (qian == 7) || (shi == 7)||(bai == 7) || (ge == 7))
{
stradd[i++] = SelectNum ;
++ Count;
}
}
SelectNum = 7 ;
while( SelectNum <= num )
{
++ Count ;
strmut[j++] = SelectNum ;
SelectNum += 7 ;
}
for( ii = 0; ii < i ; ii ++)
{
for( jj = 0; jj < j; jj ++)
{
if(stradd [ii] == strmut[jj])
{
++same;
}
}
}
/* for(k = 0 ;k<i;k++)
printf("%d ",stradd[k]);
printf("\n");
for(k = 0 ;k<j;k++)
printf("%d ",strmut[k]);
printf("\n");
printf("%d\n",Count);
printf("%d\n",same);
*/
printf("%d",(Count - same));
}
}
【C语言代码】从整数N内挑‘7’
最新推荐文章于 2023-05-14 16:57:50 发布