Question

Help needed in c program ! Thannx

Write a C code to calculate the following piecewise function using switch. Assume user enters x (a real number) tan(x +1) 10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include<math.h>

int main()
{ float x;
float value;
int y;
printf("enter x values\n");
scanf("%f",&x);
if(x>0)
y=1;
else if(x==0)
y=2;
else
y=3;
switch(y){
case 1:
value=tan(x+1) ;

printf("function f(x) is %.3f\n",value);
break;
case 2:
value=10;
printf("function f(x) is %.3f\n",value);
break;
case 3:
value=pow(x-1,1/3)-pow(x+5,1/5);
printf("function f(x) is %.3f\n",value);
break;
default:
printf("yo have entered an improper input");
}
return 0;
}

#include <stdio.h> #include«math.h> int main() float x; float value; int y: printf(enter x scanf(%f, &x); if(x>0) values \

enter x values 1.3 function f(x) is -1.119

enter x values function f(x) is 10.000

enter x values 0.3 function f(x) is 3.602

Add a comment
Know the answer?
Add Answer to:
Write a C code to calculate the following piecewise function using switch. Assume user enters x (...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a Matlab function, piecewise (), that will calculate and return the value of the...

    1. Write a Matlab function, piecewise (), that will calculate and return the value of the function f(x) defined by: 0<rS3 3<s5 e (x) -cos(3r) 2 sin(r) 2. Write a Matlab script to plot the function f(z) on the interval -3ss8. Ensure the output is sufficiently smooth by declaring z with enough data points. The plot should include the title My Piecewise Function, appropriate axis labels and grid lines. 1. Write a Matlab function, piecewise (), that will calculate and...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • Solve using C language The mathematician Euler proved that: tan-(x) = x -. Write a C...

    Solve using C language The mathematician Euler proved that: tan-(x) = x -. Write a C program to do the following: -Ask user to enter the value of (x) radians, -0.5<=x<=0.5. -Calculate and print the actual value atan (x)in degrees. - Use loops to calculate and print the series sum in degrees. -loop should stop when absolute difference between actual and series sum become <=10-3. -Print out number of iterations needed to get the result. - The program should run...

  • Write a C code using switch statement that will ask the user to enter a character....

    Write a C code using switch statement that will ask the user to enter a character. This character should be one of the first three characters of your name. The code then should check for the value of the character and output the following: If the character is the same as yo&r first letter then output "X=10" If the character is the same as your second letter then output "Y=5" If the character is the same as your Third letter...

  • Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...

    Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...

  • Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func:...

    Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func: the function/equation that you are required to integrate -a, b: the integration limits n: the number of points to be used for the integration I:Integral estimate a) Write a function capable of performing numerical integration of h(x) using the composite trapezoidal rule. Use your function to integration the equation with 9 points. Write a function capable of performing numerical integration of h(x) using the...

  • Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle...

    Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle 2. Area of square 3. Area of rectangle The program should use the following functions properly: void displayMenu() //a function that will display the menu options to the user int getChoice() //a function that will input the user choice and returns it float calculate(int choice) //a function that reads the required inputs based on the user choice, and returns the area of the shape...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • using c++ write a program that reads numbers from the user until the user enters a...

    using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: 1. Output the sum of all even numbers

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT