怎么把他写成函数
选出能被3整除且至少有一位是5的两位数,输出所有这样的数及其个数。#include <stdio. h>
sub (intk, int n){
}
main()
int n=0, k,m;
for(k=10;k<=99;k++) { m=sub(k,n) ;
if (m!=-1)n=m;
}
printf ("这样的数有%d",n)
}
2019-06-11 22:23
2019-06-11 23:02
程序代码:#include <stdio.h>
_Bool sub( unsigned n )
{
return n%3==0 && (n%10==5 || n/10==5);
}
int main( void )
{
unsigned count = 0;
for( unsigned i=10; i<=99; ++i )
{
if( sub(i) )
{
printf( "%u\n", i );
++count;
}
}
printf( "这样的数有 %u 个\n", count );
}
2019-06-12 08:36