


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











If you suspect your hard drive encounters issues, you can check the drive for errors on Windows 7. This php.cn post talks about fixdisk Windows 7. You can follow the guide to check the hard drive for errors on Windows 7.

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

Have you ever encountered a black screen after installing a graphics driver like an Nvidia driver in Windows 10/11? Now in this post from php.cn, you can find a couple of worth trying solutions to the Nvidia driver update black screen.

KB2267602 is a protection or definition update for Windows Defender designed to fix vulnerabilities and threats in Windows. Some users reported that they were unable to install KB2267602. This post from php.cn introduces how to fix the “KB2267602 fai

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.

File system errors commonly happen on people’s computer and the error can trigger a series of linked malfunctions. This article on php.cn Website will give you a series of fixes to targeting the file system error (-1073741521). Please keep on with yo

Are you suffering from the error message "FileType selected not supported by this app" when opening files in Teams or Excel? Now read this post from php.cn to get several useful solutions to this issue.

The Security tab in File Properties helps set different permissions for different groups and users to a file or folder. Some users find that Windows 11 Security tab missing from File Properties. This post from php.cn gives some methods to fix it.
