


Design a function in C language to implement addition, subtraction, multiplication and division operations
Design a function in C language to implement addition, subtraction, multiplication and division operations
# include
double jia(double x, double d)
{
double s;
s = x d;
return s;
}
double jian(double x, double d)
{
double s;
s = x-d;
return s;
}
double cheng(double x, double d)
{
double s;
s = x*d;
return s;
}
double chu(double x, double d)
{
double s;
s = x/d;
return s;
}
int main(void)
{
double i, j, k;
char t;
k = 0;
printf ("Please enter what operation you want to calculate" ""-""*""/"\n");
scanf("%c", &t);
if(t == ' ')
{
printf("Please enter the two numbers to be added\n");
scanf("%lf %lf", &i, &j);
k = jia(i, j);
printf ("The sum of these two numbers is %6.2lf\n", k);
}
else if(t == '-')
{
printf("Please enter the two numbers to be subtracted\n");
scanf("%lf %lf", &i, &j);
k = jian(i, j);
printf ("The subtraction of these two numbers is %6.2lf\n", k);
}
else if(t == '*')
{
printf("Please enter the two numbers to be compared\n");
scanf("%lf %lf", &i, &j);
k = cheng(i, j);
printf ("The phase of these two numbers is %6.2lf\n", k);
}
else if(t == '/')
{
printf("Please enter the two numbers you want to compare\n");
scanf("%lf %lf", &i, &j);
k = chu(i, j);
printf ("These two numbers are %6.2lf\n", k);
}
else
{
printf ("Sorry, currently only supports """-""*""/"\n");
}
return 0;
}
How to write a C language program to let the computer automatically perform four arithmetic calculations
#include
#include
#include
#include
int main()
{
int type;
int left, right;
float result;
srand(unsigned(time(NULL)));
while(1)
{
type = rand() % 4;
left = rand() % 10;
right = rand() % 10;
switch(type)
{
case 0:
printf("%d %d = ?\n", left, right);
scanf("%f", &result);
if(left right == result)
printf("right!\n");
else
printf("wrong!The result is %d\n", left right);
break;
case 1:
printf("%d - %d = ?\n", left, right);
scanf("%f", &result);
if(left - right == result)
printf("right!\n");
else
printf("wrong!The result is %d\n", left - right);
break;
case 2:
printf("%d * %d = ?\n", left, right);
scanf("%f", &result);
if(left * right == result)
printf("right!\n");
Use the basic library classes of java to implement a program that calculates four arithmetic operations
package Ex1; //Ex1 is the package name
import java.util.*;
public class SzYs { //SzYs is the class name
public static void main(String[] args){
double num1;
double num2;
String fuHao;
Scanner input = new Scanner(System.in);
System.out.print("Enter the value of the first number:");
num1 = input.nextDouble();
System.out.print("Enter the value of the second number:");
num2 = input.nextDouble();
System.out.print("Enter operation symbol (- * \\)");
fuHao = input.next();
if(fuHao.equals("")){
System.out.print(The sum of num1 " and " num2 " is " (num1 num2));
}else if(fuHao.equals("-")){
System.out.print(The difference between num1 " and " num2 " is " (num1-num2));
}else if(fuHao.equals("8")){
System.out.print(The product of num1 " and " num2 " is " (num1*num2));
}else if(fuHao.equals("\\")){
if(num2==0){
System.out.print("The divisor cannot be 0");
}else{
System.out.print(The quotient of num1 " and " num2 " is " (num1/num2));
}
}else{
System.out.print("The symbol cannot be recognized");
}
}
}
The above is the detailed content of Design a function in C language to implement addition, subtraction, multiplication and division operations. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004)

ENE SYS Maintenance: Tips and Tricks to Keep Your System Running Smoothly

5 Common Mistakes to Avoid During ENE SYS Implementation

How do I edit the Registry? (Warning: Use with caution!)

Discover How to Fix Drive Health Warning in Windows Settings
