Current location - Training Enrollment Network - Mathematics courses - C language calculator function requirements: can input numbers, decimal points, positive numbers and negative numbers from 0 to 9, and can perform addition, subtraction, multiplication and division op
C language calculator function requirements: can input numbers, decimal points, positive numbers and negative numbers from 0 to 9, and can perform addition, subtraction, multiplication and division op
C language calculator function requirements: can input numbers, decimal points, positive numbers and negative numbers from 0 to 9, and can perform addition, subtraction, multiplication and division operations and simple mathematical function operations? The following is a sample code for designing a simple scientific calculator using C language:

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & ltmath.h & gt

int main()

{

char op

Double num 1, num2

Printf ("Please enter a mathematical expression (such as:1+2):");

scanf("%lf %c %lf ",& ampnum 1。 Operational amplifier. num 2);

switch

{

Case "+":

Printf ("Result: %.2lf\n ",num 1+num 2);

Break;

Case'-':

Printf ("Result: %.2lf\n ",num 1-num 2);

Break;

Case' *':

Printf ("Result: %.2lf\n ",num 1 * num 2);

Break;

Case "/":

if (num2 == 0)

{

Printf ("divisor cannot be 0! \ n ");

}

other

{

Printf ("Result: %.2lf\n ",num 1/num 2);

}

Break;

Keith'':

Printf ("Result: %.2lf\n", pow(num 1, num 2)););

Break;

Case:

Printf ("Result: %.2lf\n", SIN (num1));

Break;

Case "c":

Printf ("Result: %.2lf\n", COS (num1));

Break;

Case "t":

Printf ("Result: %.2lf\n", Tan (num1));

Break;

Case "l":

Printf ("Result: %.2lf\n ",log(num 1));

Break;

Case "e":

Printf ("Result: %.2lf\n ",exp(num 1));

Break;

Default value:

Printf ("Invalid operator! \ n ");

Break;

}

Returns 0;

}