c Programming
Convert the following switch-case code to if-else code.
Convert Switch case into If-else
C program ==>
#include
#include
// convert switch case into if else;
int main()
{
int j,k;
printf("Enter j \n");
scanf("%d",&j);
if( j>=0 && j<=2)
{
k=20;
}
else if (j==3)
{
k=250;
}
else
{
k=1;
}
printf(" The value of j is %d \n",j);
printf(" The value of K is %d \n",k);
return 0;
}
Code Screenshot ===>
Output Screenshot ===>
1) Convert the "Switch" statement to "if/else" 2) Convert from for loop to while loop Convert the following "switch" statement to an equivalent "if/else": switch(x) case 10: cost- 1; break; case 20: cost- 2; break; default: cost 0; 0 if (cost =-1) x = 1; else if (cost-20) x = 2; else x = 0; O if ( x = 10) cost = 1; else if (x = 2) cost-20; else cost = 0; if (case10) cost 1; else if...
C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...
[C#] I need to convert this if/else statements into Switch I have the code for the if/else but now need to turn it into a switch. The Console.WriteLine and all that is fine. I just need to convert the if/else. int x1, x2, y1, y2; Console.WriteLine("What is smallest value of x:"); x1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("What is largest value of x:"); x2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("What is smallest value of y:"); y1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("What is largest value of y:"); y2 =...
Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }
5. Consider the following C code: int main() int x = 1; switch (x) case 1: i=1; case 2: i=5; return 0; Based on this code, answer the following: (a) Convert the above C code to MIPS assembly. (b) The condition you are testing is met at Case 1. You do not want the Case 2 to be tested. Add appropriate instructions in MIPS for this implementation. (c) If int x is any integer other than 1 or 2, you...
QUESTION 18 Rewrite this if/else if code segment into a switch statement int num = 0; int a = 10, b = 20, c = 20, d = 30, x = 40; if (num > 101 && num <= 105) { a += 1; } else if (num == 208) { b += 1; X = 8; } else if (num > 208 && num <210) { c=c* 3; } else { d+= 1004;
Java programming For the following problem statement, would you include an if/else statement or a switch statement? Explain your answer. Be sure to address both types of statements in your answer. (You do not need to write the code.) [3 Points] Write a program that determines the bonus that should be paid to employees. Bonuses are determined based on the year’s production. The bonus is $25 for 1000 units or fewer. The bonus is $50 for 1001 to 3000 units....
I want c++ code for employee payslip calculation using switch statement convert this code to switch statement also, use for loop ___________________________________________________________________________ #include using namespace std; int main() {char empname[222]; float basicSalary, h_r_a, DearnessAllow, tax, netSalary; int e_id; cout<<"\nEmployee Name :"; cin>>empname; cout<<"\nEmployee Id :"; cin>>e_id; cout << "Enter Basic Salary : "; cin >> basicSalary; DearnessAllow = 0.30 * basicSalary; h_r_a= 800; tax = 0.10 * basicSalary; netSalary = basicSalary + DearnessAllow + h_r_a - tax; cout<<"\nEmployee Id :...
5) Consider the following Verilog code if (A) y- 1 else if (B) y-2 else if (C) y 3 else if (D) y 4 else у 0; Show what would most likely be synthesized. 6) Rewrite the code from the previous problem as a case statement. Show what would be synthesized if the parallel case synthesis directive is used. 5) Consider the following Verilog code if (A) y- 1 else if (B) y-2 else if (C) y 3 else if...
Convert the following code to assembly MIPS void checki() { int i = 0; while(i < 10) { switch(i) { case 1: i += 5; break; case 2: i --; break; case 3: i += 2; break; default: i++; } } } void main() { checki(); }