C语言编程 4个号码按照从大到小的顺序组成一个数字可被11整除,颠倒过来也可被11整除,求这样的4个号码。

来源:百度知道 编辑:UC知道 时间:2024/06/30 20:32:45
各位高手请速度!正确的话有加分!

#include <stdio.h>

int main()
{
for (int a = 0; a < 10; ++a)
for (int b = a; b < 10; ++b)
for (int c = b; c < 10; ++c)
for (int d = c; d < 10; ++d)
if ((a + b * 10 + c * 100 + d * 1000) % 11 == 0
&& (a * 1000 + b * 100 + c * 10 + d) % 11 == 0)
{
printf("%d %d %d %d\n", a, b, c, d);
}
return 0;
}

这个题目的解太多,从10以上的就开始有了
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
int a,b,c,d;
char str[100] = {0};
char shu[10] = {0};
for (a = 1; a <= 50; a++)
{
for (b = a+1; b <= 50; b++)
{
for (c = b+1; c <= 50; c++)
{
for (d = c+1; d <= 50; d++)
{
memset(str, 0, 100);
itoa(a, shu, 10);
strcat(str, shu);
memset(shu, 0, 10);
itoa(b, shu, 10);
strcat(str, shu);
memset(s