V
Ich habs mal anders eingetippt.
#include <iostream>
#include <cmath>
using namespace std;
double ziel;
double bestes;
void test3(double a,double b,double c) {
{
double x=a+b+c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'+'<<b<<'+'<<c<<'='<<x<<'\n';
}
}
{
double x=a+b-c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'+'<<b<<'-'<<c<<'='<<x<<'\n';
}
}
{
double x=a+(b-c);
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'+'<<'('<<b<<'-'<<c<<')'<<'='<<x<<'\n';
}
}
{
double x=a+b*c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'+'<<b<<'*'<<c<<'='<<x<<'\n';
}
}
{
double x=(a+b)*c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<'('<<a<<'+'<<b<<')'<<'*'<<c<<'='<<x<<'\n';
}
}
{
double x=a+b/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'+'<<b<<'/'<<c<<'='<<x<<'\n';
}
}
{
double x=(a+b)/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<'('<<a<<'+'<<b<<')'<<'/'<<c<<'='<<x<<'\n';
}
}
{
double x=a-b-c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'-'<<b<<'-'<<c<<'='<<x<<'\n';
}
}
{
double x=a-(b-c);
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'-'<<'('<<b<<'-'<<c<<')'<<'='<<x<<'\n';
}
}
{
double x=a-b*c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'-'<<b<<'*'<<c<<'='<<x<<'\n';
}
}
{
double x=(a-b)*c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<'('<<a<<'-'<<b<<')'<<'*'<<c<<'='<<x<<'\n';
}
}
{
double x=a-b/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'-'<<b<<'/'<<c<<'='<<x<<'\n';
}
}
{
double x=(a-b)/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<'('<<a<<'-'<<b<<')'<<'/'<<c<<'='<<x<<'\n';
}
}
{
double x=a*b*c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'*'<<b<<'*'<<c<<'='<<x<<'\n';
}
}
{
double x=a*b/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'*'<<b<<'/'<<c<<'='<<x<<'\n';
}
}
{
double x=a/b/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'/'<<b<<'/'<<c<<'='<<x<<'\n';
}
}
{
double x=(a/b)/c;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<'('<<a<<'/'<<b<<')'<<'/'<<c<<'='<<x<<'\n';
}
}
}
void test3(double a,double b) {
{
double x=a+b;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'+'<<b<<'='<<x<<'\n';
}
}
{
double x=a-b;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'-'<<b<<'='<<x<<'\n';
}
}
{
double x=a*b;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'*'<<b<<'='<<x<<'\n';
}
}
{
double x=a/b;
double d=abs(x-ziel);
if (d<=bestes) {
bestes=d;
cout<<a<<'/'<<b<<'='<<x<<'\n';
}
}
}
void test2(double a,double b,double c) {
test3(a,b,c);
test3(a,b,10*c);
test3(a,10*b,c);
test3(a,10*b,10*c);
test3(10*a,b,c);
test3(10*a,b,10*c);
test3(10*a,10*b,c);
test3(10*a,10*b,10*c);
test3(10*a+b,c);
test3(10*a+c,b);
test3(10*b+a,c);
test3(10*b+c,a);
test3(10*c+a,b);
test3(10*c+b,a);
}
void test1(double a,double b,double c) {
test2(a,b,c);
test2(a,c,b);
test2(b,a,c);
test2(b,c,a);
test2(c,a,b);
test2(c,b,a);
}
int main() {
int a=3;
int b=2;
int c=1;
ziel=31;
bestes=1000;
test1(a,b,c);
return 0;
}
30+2-1=31
30+(2-1)=31
32-1=31
30-(1-2)=31
32-1=31
2+30-1=31
2+(30-1)=31
32-1=31
2-(1-30)=31
32-1=31
32-1=31
32-1=31