5 5 5 5 5 = 5 fill in subtraction
#include <stdio.h>int main () {int j,i[5];int sign;int result;int count;int num[6];float left ,right;char oper[5]={' ', ' + ', '-', ' * ', '/'};p rintf ("Please enter 5 numbers:"); for (j=1;j <=5;j++) scanf ("%d", &num[j]);p rintf ("Please enter results:"), scanf ("%d", &result), for (i[1]=1;i[1]<=4;i[1]++) {if ( I[1]<4) | | (num[2]!=0) ) {for (i[2]=1;i[2]<=4;i[2]++) {if ((i[2]<4) | | (num[3]!=0)) {for (i[3]=1;i[3]<=4;i[3]++) {if (i[3]<4) | | | num[4]!=0) {for (i[4]=1;i[4]<=4;i[4]++) {if ((i[4]<4) | | | (num[5]!=0)) {left = 0;right = num[1];sign =1;for (j=1;j<=4;j++) {switch (oper[i[j]) {case ' + ':left =left + sign*right;sign = 1;right = num [j+1];break;case ' -': left = left + sign*right;sign = -1;right = num[j+1];break;case ' * ':right = right*num[j+1];break;case '/': Right = right/num[j+1];break;}} if (Left+sign*right == result) {count++;p rintf ("%3d: ", Count), for (j=1;j<=4;j++) printf ("%d%c", Num[j],oper[i[j]);p rintf ("%d=%d\n" , Num[5],result);}}}}}} if (count == 0) printf ("There is no way to meet the requirements!") \ n "); Getch () ;return 0;}
Data Structure Enumeration Learning notes