c语言编程题,计算二十四点 随机生成四个1~10的数字,使用加减乘除运算,计算24.输出这四个数字是否能计算
展开全部
最随机数1-10 赋值A,最随机数1-赋值B,共赋值ABCD,叛断,赋值A等于BCD,则重取随机数,然后叛断用ABCD相加或减等于24,等则输出,不等于则重取。
#include "stdlib.h"
#include "stdio.h"
} NODE24;
NODE24 head;int res=24;int maketree(int *src,int *i, NODE24 *p)
{
int d=src[*i];
(*i)++;
case '/':
p->left=new NODE24;
p->right=new NODE24;
p->left=NULL;
p->right=NULL;
扩展资料:
随机数是专门的随机试验的结果。
在统计学的不同技术中需要使用随机数,比如在从统计总体中抽取有代表性的样本的时候,或者在将实验动物分配到不同的试验组的过程中,或者在进行蒙特卡罗模拟法计算的时候等等。
产生随机数有多种不同的方法。这些方法被称为随机数生成器。随机数最重要的特性是它在产生时后面的那个数与前面的那个数毫无关系。
参考资料来源:百度百科-随机数
展开全部
很简单呀。最随机数1-10 赋值A,最随机数1-赋值B,。。。。共赋值ABCD,叛断,赋值A等于BCD,则重取随机数,然后叛断用ABCD相加或减等于24,等则输出。不等于则重取
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <string.h>
int c24;
char expr3[80];
char expr4[80];
void count2( int a, int b )
{
if ( a + b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d+%d=24\n", expr4, expr3, a, b );
}
if ( a * b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d+%d=24\n", expr4, expr3, a, b );
}
if ( a * b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d*%d=24\n", expr4, expr3, a, b );
}
if ( a - b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d-%d=24\n", expr4, expr3, a, b );
}
if ( b - a == 24 )
{
c24 ++;
printf( "%s\t%s\t%d-%d=24\n", expr4, expr3, b, a );
}
if ( (b!=0) && (a==24*b) )
{
c24 ++;
printf( "%s\t%s\t%d/%d=24\n", expr4, expr3, a, b );
}
if ( (a!=0) && (b==24*a) )
{
c24 ++;
printf( "%s\t%s\t%d/%d=24\n", expr4, expr3, b, a );
}
}
void count3( int a, int b, int c )
{
int dd[3];
int i,j,k,nd;
dd[0] = a;
dd[1] = b;
dd[2] = c;
for ( i = 0; i < 3; i++ )
for ( j = i+1; j < 3; j++ )
{
k = 3 - i - j;
nd = dd[i] + dd[j];
sprintf( expr3, "%d+%d=%d", dd[i], dd[j], nd );
count2( nd, dd[k] );
nd = dd[i] * dd[j];
sprintf( expr3, "%d*%d=%d", dd[i], dd[j], nd );
count2( nd, dd[k] );
if ( dd[i]>dd[j] )
{
nd = dd[i] - dd[j];
sprintf( expr3, "%d-%d=%d", dd[i], dd[j], nd );
}
else
{
nd = dd[j] - dd[i];
sprintf( expr3, "%d-%d=%d", dd[j], dd[i], nd );
}
count2( nd, dd[k] );
if ( (dd[j]!=0) && (dd[i]%dd[j]==0) )
{
nd = dd[i] / dd[j];
sprintf( expr3, "%d/%d=%d", dd[i], dd[j], nd );
count2( nd, dd[k] );
}
else if ( (dd[i]!=0) && (dd[j]%dd[i]==0) )
{
nd = dd[j] / dd[i];
sprintf( expr3, "%d/%d=%d", dd[j], dd[i], nd );
count2( nd, dd[k] );
}
}
}
void count4( int a, int b, int c, int d )
{
int dd[4];
int i,j,k,m,nd; dd[0] = a;
dd[1] = b;
dd[2] = c;
dd[3] = d;
for ( i = 0; i < 4; i++ )
for ( j = i+1; j < 4; j++ )
{
for ( k = 0; (k==i) || (k==j); k++ ) ;
m = 6 - i - j - k;
nd = dd[i] + dd[j];
sprintf( expr4, "%d+%d=%d", dd[i], dd[j], nd );
count3( nd, dd[k], dd[m] );
nd = dd[i] * dd[j];
sprintf( expr4, "%d*%d=%d", dd[i], dd[j], nd );
count3( nd, dd[k], dd[m] );
if ( dd[i]>dd[j] )
{
nd = dd[i] - dd[j];
sprintf( expr4, "%d-%d=%d", dd[i], dd[j], nd );
}
else
{
nd = dd[j] - dd[i];
sprintf( expr4, "%d-%d=%d", dd[j], dd[i], nd );
}
count3( nd, dd[k], dd[m] );
if ( (dd[j]!=0) && (dd[i]%dd[j]==0) )
{
nd = dd[j] / dd[i];
sprintf( expr4, "%d/%d=%d", dd[j], dd[i], nd );
count3( nd, dd[k], dd[m] );
}
}
}
main()
{
int a,b,c,d;
printf( "Input 4 Number for Count 24: " );
scanf( "%d%d%d%d", &a, &b, &c, &d );
c24 = 0;
count4( a, b, c, d );
if ( c24==0 )
printf( "=======failed======\n" ); /***/
printf("End of C Program, Press Enter.\n");
getchar();
getchar();
return 0;
}
#include <string.h>
int c24;
char expr3[80];
char expr4[80];
void count2( int a, int b )
{
if ( a + b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d+%d=24\n", expr4, expr3, a, b );
}
if ( a * b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d+%d=24\n", expr4, expr3, a, b );
}
if ( a * b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d*%d=24\n", expr4, expr3, a, b );
}
if ( a - b == 24 )
{
c24 ++;
printf( "%s\t%s\t%d-%d=24\n", expr4, expr3, a, b );
}
if ( b - a == 24 )
{
c24 ++;
printf( "%s\t%s\t%d-%d=24\n", expr4, expr3, b, a );
}
if ( (b!=0) && (a==24*b) )
{
c24 ++;
printf( "%s\t%s\t%d/%d=24\n", expr4, expr3, a, b );
}
if ( (a!=0) && (b==24*a) )
{
c24 ++;
printf( "%s\t%s\t%d/%d=24\n", expr4, expr3, b, a );
}
}
void count3( int a, int b, int c )
{
int dd[3];
int i,j,k,nd;
dd[0] = a;
dd[1] = b;
dd[2] = c;
for ( i = 0; i < 3; i++ )
for ( j = i+1; j < 3; j++ )
{
k = 3 - i - j;
nd = dd[i] + dd[j];
sprintf( expr3, "%d+%d=%d", dd[i], dd[j], nd );
count2( nd, dd[k] );
nd = dd[i] * dd[j];
sprintf( expr3, "%d*%d=%d", dd[i], dd[j], nd );
count2( nd, dd[k] );
if ( dd[i]>dd[j] )
{
nd = dd[i] - dd[j];
sprintf( expr3, "%d-%d=%d", dd[i], dd[j], nd );
}
else
{
nd = dd[j] - dd[i];
sprintf( expr3, "%d-%d=%d", dd[j], dd[i], nd );
}
count2( nd, dd[k] );
if ( (dd[j]!=0) && (dd[i]%dd[j]==0) )
{
nd = dd[i] / dd[j];
sprintf( expr3, "%d/%d=%d", dd[i], dd[j], nd );
count2( nd, dd[k] );
}
else if ( (dd[i]!=0) && (dd[j]%dd[i]==0) )
{
nd = dd[j] / dd[i];
sprintf( expr3, "%d/%d=%d", dd[j], dd[i], nd );
count2( nd, dd[k] );
}
}
}
void count4( int a, int b, int c, int d )
{
int dd[4];
int i,j,k,m,nd; dd[0] = a;
dd[1] = b;
dd[2] = c;
dd[3] = d;
for ( i = 0; i < 4; i++ )
for ( j = i+1; j < 4; j++ )
{
for ( k = 0; (k==i) || (k==j); k++ ) ;
m = 6 - i - j - k;
nd = dd[i] + dd[j];
sprintf( expr4, "%d+%d=%d", dd[i], dd[j], nd );
count3( nd, dd[k], dd[m] );
nd = dd[i] * dd[j];
sprintf( expr4, "%d*%d=%d", dd[i], dd[j], nd );
count3( nd, dd[k], dd[m] );
if ( dd[i]>dd[j] )
{
nd = dd[i] - dd[j];
sprintf( expr4, "%d-%d=%d", dd[i], dd[j], nd );
}
else
{
nd = dd[j] - dd[i];
sprintf( expr4, "%d-%d=%d", dd[j], dd[i], nd );
}
count3( nd, dd[k], dd[m] );
if ( (dd[j]!=0) && (dd[i]%dd[j]==0) )
{
nd = dd[j] / dd[i];
sprintf( expr4, "%d/%d=%d", dd[j], dd[i], nd );
count3( nd, dd[k], dd[m] );
}
}
}
main()
{
int a,b,c,d;
printf( "Input 4 Number for Count 24: " );
scanf( "%d%d%d%d", &a, &b, &c, &d );
c24 = 0;
count4( a, b, c, d );
if ( c24==0 )
printf( "=======failed======\n" ); /***/
printf("End of C Program, Press Enter.\n");
getchar();
getchar();
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
什么意思,我不懂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询