有兴趣的试试吧,很有意思。
有想看源码的说一声,我这里有C和C++的版本。
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\user_child\桌面\算24的C程序\新建文件夹\Cpp1.cpp(175) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::al
locator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
C:\Documents and Settings\user_child\桌面\算24的C程序\新建文件夹\Cpp1.cpp(175) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocato
r<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
d:\download\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std::basic_string<
char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
d:\download\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<std::basic_string
<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
Linking...
Cpp1.exe - 0 error(s), 4 warning(s)
什么意思哦???
没时间琢磨 网上有很多吧
----code quoted from google----
#include <stdio.h>
#include<math.h>
float a[4];
void cpl(int,int);
void count24();
float computer(float,float,int);
void main()
{
int i;
printf("Please input 4 number\n");
printf("The number should >0 and <14\n");
for(i=0;i<4;i++){
do{
scanf("%f",&a[i]);
if(a[i]<1||a[i]>13){
printf("The number is error\n");
}
}while(a[i]<1||a[i]>13);
}
cpl(0,4);
}
void cpl(int m, int n)
{
int i;
float t;
if (m<n-1) {
cpl(m+1, n);
for (i=m+1;i<n;i++) {
t=a[m]; a[m]=a[i]; a[i]=t;
cpl(m+1, n);
t=a[m]; a[m]=a[i]; a[i]=t;
}
} else
{
count24();
}
}
void count24()
{
int i,j,k;
float b[3];
char s[5]= "+-*/";
for(i=0;i<4;i++){
for(j=0;j<4;j++){
for(k=0;k<4;k++){
b[0]=computer(a[0],a[1],k);
b[1]=computer(b[0],a[2],j);
b[2]=computer(b[1],a[3],i);
if((abs(b[2]-24))<0.000001){
printf("%f= %f %c %f\n",b[0],a[0],s[k],a[1]);
printf("%f = %f %c %f\n",b[1],b[0],s[j],a[2]);
printf("%f = %f %c %f\n\n\n ",b[2],b[1],s[i],a[3]);
}
}
}
}
}
float computer(float m,float n,int op)
{
float temp;
switch(op){
case 0:
temp=m+n;
break;
case 1:
temp=m-n;
break;
case 2:
temp=m*n;
break;
case 3:
temp=m/n;
break;
}
return temp;
}