Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello , I have to finish a MIPS project, but I don't know how to do it , some one who can help me transfer

Hello , I have to finish a MIPS project, but I don't know how to do it , some one who can help me transfer from the C language to MIPS. Thank you so much

#include

char op[5]={'#', '+', '-', '*', '/',};

float cal(float x, float y, int op)

{

switch(op)

{

case 1: return x+y;

case 2: return x-y;

case 3: return x*y;

case 4: return x/y;

default: return 0.0;

}

}

float calculate_model1(float i, float j, float k, float t, int op1, int op2, int op3)

{

float r1, r2, r3;

r1 = cal(i, j, op1);

r2 = cal(r1, k, op2);

r3 = cal(r2, t, op3);

return r3;

}

float calculate_model2(float i, float j, float k, float t, int op1, int op2, int op3)

{

float r1, r2, r3;

r1 = cal(j, k, op2);

r2 = cal(i, r1, op1);

r3 = cal(r2, t, op3);

return r3;

}

float calculate_model3(float i, float j, float k, float t, int op1, int op2, int op3)

{

float r1, r2, r3 ;

r1 = cal(k, t, op3);

r2 = cal(j, r1, op2);

r3 = cal(i, r2, op1);

return r3;

}

float calculate_model4(float i, float j, float k, float t, int op1, int op2, int op3)

{

float r1, r2, r3;

r1 = cal(j, k, op2);

r2 = cal(r1, t, op3);

r3 = cal(i, r2, op1);

return r3;

}

float calculate_model5(float i,float j,float k,float t,int op1,int op2,int op3)

{

float r1, r2, r3 ;

r1 = cal(i, j, op1);

r2 = cal(k, t, op3);

r3 = cal(r1, r2, op2);

return r3;

}

int get24(int i, int j, int k, int t)

{

int op1, op2, op3;

int flag=0;

for(op1=1; op1<=4; op1++)

for(op2=1; op2<=4; op2++)

for(op3=1; op3<=4; op3++)

{

if(calculate_model1(i, j, k, t, op1, op2, op3)==24)

{

printf("((%d%c%d)%c%d)%c%d=24 ", i, op[op1], j, op[op2], k, op[op3], t);

flag = 1;

}

if(calculate_model2(i, j, k, t, op1, op2, op3)==24)

{

printf("(%d%c(%d%c%d))%c%d=24 ", i, op[op1], j, op[op2], k, op[op3], t);

flag = 1;

}

if(calculate_model3(i, j, k, t, op1, op2, op3)==24)

{

printf("%d%c(%d%c(%d%c%d))=24 ", i, op[op1], j, op[op2], k, op[op3], t);

flag = 1;

}

if(calculate_model4(i, j, k, t, op1, op2, op3)==24)

{

printf("%d%c((%d%c%d)%c%d)=24 ", i, op[op1], j, op[op2], k, op[op3], t);

flag = 1;

}

if(calculate_model5(i, j, k, t, op1, op2, op3)==24)

{

printf("(%d%c%d)%c(%d%c%d)=24 ", i, op[op1], j, op[op2], k, op[op3], t);

flag = 1;

}

}

return flag;

}

int main()

{

int i, j, k, t;

printf("Please input four integer (1~10) ");

loop: scanf("%d %d %d %d", &i, &j, &k, &t);

if(i<1||i>10 || j<1||j>10 || k<1||k>10 || t<1||t>10)

{

printf("Input illege, Please input again ");

goto loop;

}

if( get24(i, j, k, t) );

else

printf("Sorry, the four integer cannot be calculated to get 24 ");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

Students also viewed these Databases questions

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago

Question

d. What language(s) did they speak?

Answered: 1 week ago

Question

e. What difficulties did they encounter?

Answered: 1 week ago