1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tatiana [17]
3 years ago
10

Write a program in c or c++ to perform different arithmeticoperation using switch statement .the program will take two inputinte

gers from the user and then an arithmetic operator from theuser to perform the specific operation the given twointegers?

Computers and Technology
1 answer:
baherus [9]3 years ago
6 0

Answer:

C code :

#include<stdio.h>

int main()

{

int j;

float k,l, x;  //taking float to give the real results.

printf("Enter your two operands: ");  //entering the numbers on which      //the operation to be performed.

scanf("%f %f", &k, &l);

 

printf("\n Now enter the operation you want to do: ");

printf("1 for Addition, 2 for Subtraction, 3 for Multiplication, 4 for Division ");

scanf("%d", &j);  //j takes the input for opearation.

 

switch(j)  

{

 case 1:  

  x=k+l;

  printf("%.2f+%.2f=%.2f",k,l,x);   //we write %.2f to get the result //upto 2 decimal point.

  break;

   

 case 2:

  x=k-l;

  printf("%.2f-%.2f=%.2f",k,l,x);

  break;

 case 3:

  x=k*l;

  printf("%.2f*%.2f=%.2f",k,l,x);

  break;

 case 4:

  if(l!=0) //division is not possible if the denominator is 0.

  {

   x=k/l;

   printf("%.2f/%.2f=%.2f",k,l,x);

  }

  else  

   printf("Division result is undefined");

               default:

   printf("\n invalid operation");

}

}

Output is in image.

Explanation:

At first we take two numbers.

Then we take integers from 1 to 4 for Addition, subtraction, multiplication, division respectively.

Then accordingly the case is followed and the operation is performed.

You might be interested in
Why is wider channel bandwidth good?
Nookie1986 [14]

Answer:

The wider channel bandwidth is efficient and good as it help in increasing the speed of the transmission. Due to the wider channel of the bandwidth it also lead to consuming less energy of the battery and make cost effective.

Due to the wider bandwidth, the number of clients can easily share and transfer the data in the channel and also make the transmission complete.

If the channel of the bandwidth is double then, the single transmission can easily carry more data. Hence, it also lead to double the speed of the transmission.

7 0
3 years ago
Write a family database program. Create a class to represent a person and to store references to the person’s mother, father, an
Gennadij [26K]

Do you go to BASIS?

Sorry I don't have an answer for you, but we have the same assignment in our AP Comp sci class.

Just wondering.

8 0
3 years ago
Which of the following is an example of how the respiratory system interacts with the circulatory system to excrete waste?
Varvara68 [4.7K]

Answer:

The veins carry oxygen depleted blood away from body parts,  hence the color blue.

Explanation:

5 0
3 years ago
Database developers use the ________ to create relationships in the database.
madreJ [45]
Is it multiple choice ?<span />
7 0
3 years ago
What controls a computer's basic operations?
S_A_V [24]
 Basic Computer Operations. Input: Information and programs are entered into the computer through Input devices such as the keyboard, disks, or through other computers via network connections or modems connected to the Internet. The input device also retrieves information off disks.
3 0
3 years ago
Other questions:
  • i see tabs named mowed and Ramsey i tried shredding them and deleting them and ending all the processes but they start duplicati
    13·1 answer
  • In your own words, describe what Internet Protocols are. Why is it important to have agreed upon protocols?
    6·1 answer
  • House real estate summary Sites like Zillow get input about house prices from a database and provide nice summaries for readers.
    11·1 answer
  • A Silicon Valley billionaire purchases 3 new cars for his collection at the end of every month. Let a_n denote the number of car
    8·1 answer
  • Which of the following is true about advertisements?
    15·1 answer
  • 3. State whether the given statements are true or false. a. The computer is called a data processor because it can store, proces
    13·1 answer
  • Your program will be used by many departments at the university. Your comments will be important to their IT people. What would
    13·1 answer
  • Write any two rules for writing algorithm​
    10·1 answer
  • When is it appropriate to utilize the nat network connection type?
    8·1 answer
  • Which of the following statements is TRUE? A. A name error occurs if the variable is referenced before it is declared. B. A name
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!