从1到33这33个书中,任意选着6个不相同的数。其和值在21到183 之间
1到16 记为小数,17到33记为大数。
要求:任意给一个和值,大小之比,奇偶之比
让其输出结果为6个数字之和。 例如: 1+2+3+4+5+6=21
大小比形式为:0:6 1:5 2:4 3:3 4:2 5:1 6:0
奇偶比形式为:0:6 1:5 2:4 3:3 4:2 5:1 6:0
1:编程思想或方法
2:流程图
3:请附上运行后的图
急啊~~~!!!!!谢谢~~~!!!!!
从1到33这33个书中,任意选着6个不相同的数。其和值在21到183 之间
1到16 记为小数,17到33记为大数。
要求:任意给一个和值,大小之比,奇偶之比
让其输出结果为6个数字之和。 例如: 1+2+3+4+5+6=21
大小比形式为:0:6 1:5 2:4 3:3 4:2 5:1 6:0
奇偶比形式为:0:6 1:5 2:4 3:3 4:2 5:1 6:0
1:编程思想或方法
2:流程图
3:请附上运行后的图
急啊~~~!!!!!谢谢~~~!!!!!
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("Please enter the sum(21~183):\n");
int addnum;
scanf("%d", &addnum);
if(21 > addnum)
{
printf("The number is too small\n");
return 1;
}
if(183 < addnum)
{
printf("The number is too large\n");
return 1;
}
printf("The result:\n\n");
int i, j, k, l, m, n;
int max, min, odd, even;
max = min = odd = even = 0;
for(i=1; i<=28; i++)
{
for(j=i+1; j<=29; j++)
for(k=j+1; k<=30; k++)
for(l=k+1; l<=31; l++)
for(m=l+1; m<=32; m++)
for(n=m+1; n<=33; n++)
{
if(addnum == i+j+k+l+m+n)
{
printf("%d+%d+%d+%d+%d+%d=%d\n", i, j, k, l, m, n, addnum);
if(16 >= i)
min ++;
else
max ++;
if(0 == i%2)
even ++;
else
odd++;
if(16 >= j)
min ++;
else
max ++;
if(0 == j%2)
even ++;
else
odd++;
if(16 >= k)
min ++;
else
max ++;
if(0 == k%2)
even ++;
else
odd++;
if(16 >= l)
min ++;
else
max ++;
if(0 == l%2)
even ++;
else
odd++;
if(16 >= m)
min ++;
else
max ++;
if(0 == m%2)
even ++;
else
odd++;
if(16 >= n)
min ++;
else
max ++;
if(0 == n%2)
even ++;
else
odd++;
printf("大小之比: %d:%d\n", max, min);
printf("奇偶之比: %d:%d\n\n", odd, even);
max = min = odd = even = 0;
}
}
}
getchar();getchar();getchar();
return 1;
}
根据您的意思,写出如下代码:
#include <stdlib.h> #include <stdio.h>
void main() { printf("Please enter the sum(21~183):\n"); int addnum; scanf("%d", &addnum); if(21 > addnum) { printf("The number is too small\n"); return; } if(183 < addnum) { printf("The number is too large\n"); return; } printf("The result:\n\n"); int i, j, k, l, m, n; int max, min, odd, even; max = min = odd = even = 0; for(i=1; i<=28; i++) { for(j=i+1; j<=29; j++) for(k=j+1; k<=30; k++) for(l=k+1; l<=31; l++) for(m=l+1; m<=32; m++) for(n=m+1; n<=33; n++) { if(addnum == i+j+k+l+m+n) { printf("%d+%d+%d+%d+%d+%d=%d\n", i, j, k, l, m, n, addnum); if(16 >= i) min ++; else max ++; if(0 == i%2) even ++; else odd++; if(16 >= j) min ++; else max ++; if(0 == j%2) even ++; else odd++; if(16 >= k) min ++; else max ++; if(0 == k%2) even ++; else odd++; if(16 >= l) min ++; else max ++; if(0 == l%2) even ++; else odd++; if(16 >= m) min ++; else max ++; if(0 == m%2) even ++; else odd++; if(16 >= n) min ++; else max ++; if(0 == n%2) even ++; else odd++; printf("大小之比: %d:%d\n", max, min); printf("奇偶之比: %d:%d\n\n", odd, even); max = min = odd = even = 0; } } }
}
如果有不明白的地方请追问。
谢谢采纳!