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
READ CAREFULLY! There is a difference between moving and copying files.a. Create a directory named . For example, mine would be
OleMash [197]

Answer:

b

Explanation:

8 0
2 years ago
What would you do if you experienced academic frustrations in school? Check all that apply.
kipiarov [429]
I think it is all of them :))
6 0
2 years ago
Read 2 more answers
Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following string
WITCHER [35]

Answer:

Explanation:

bool isPalindrome(string str)

{

   int length = str.length();

   for (int i = 0; i < length / 2; i++) {

      if (str [i] != str [length – 1 – i]) {

         return false;

         }

    }

cout << str << "is a palindrome";

return true;

}

3 0
3 years ago
The New option is found in the ...............tab.​
morpeh [17]

in your notes books and in your vopy

3 0
3 years ago
Read 2 more answers
What symbol do we use to assign a value to a variable or constant in algorithms?
jekas [21]

The symbol that we do use to assign a value to a variable or constant in algorithms is =.

<h3>What is used to assign a constant to a variable?</h3>

The const keyword is known to be one that tends to specifies a variable or object value that is known to be  constant.

In computing and computer programming, there are different kinds of variables as well as symbols that are used for different purposes.

Note that if you assign a variable, you need to use the = symbol and thus The symbol that we do use to assign a value to a variable or constant in algorithms is =.

Learn more about algorithms from

brainly.com/question/13800096

#SPJ1

3 0
1 year ago
Other questions:
  • What is faster a hi-speed usb port or superspeed usb port?
    13·1 answer
  • Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true if x
    15·1 answer
  • Charlie wants you to include the following topics in your presntation: an overview of project management and its hrity,a descrip
    15·1 answer
  • DECIPHER AND SOLVE THIS<br><br> SCC:R<br> D<br> YJOTE VP=GPIMFRT
    15·1 answer
  • How does a programmer use digital waves to transfer sound?
    11·1 answer
  • Consider the following method, which is intended to return the index of the first negative integer in a given array of integers.
    14·1 answer
  • Please help ASAP!
    7·2 answers
  • The equals method of the Object class returns true only if the two objects being compared:_________
    15·1 answer
  • True or false FAFSA awards work study, but jobspeaker can be used to learn which jobs are available
    12·1 answer
  • Global communication and transportation technologies are an example of a(n) ____
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!