Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment focuses on creating, manipulating, and displaying arithmetic exp

ID: 3639049 • Letter: T

Question

This assignment focuses on creating, manipulating, and displaying arithmetic expressions

Instructions
Create a program called arithmetic.c that does the following:

1.Prompt for and accept an unsigned short int value
2.Display the value of 2 raised to the power of the value input in (1), i.e. display 2n, where n is the value from (1)
3.Prompt for and accept an unsigned short int value, and assume that this is the radius of a circle
43)
5.Prompt for and accept a float value

6.Display the value of the polynomial 2x3 + 3x2 + 4x + 5, where x is the value read in (5)
.

Sample Output

Program: Arithmetic Expressions
Author: Doug Jones
Enter unsigned short int: 3
The value of 2 raised to the 3 power is 8
Enter unsigned short int: 5
A circle with radius 5 has circumference of 31.416 and an area of 78.540
Enter a float value: 2.5
The value of 2(2.5)**3 + 3(2.5)**2 + 4(2.5) + 5 = 65




Explanation / Answer

1) You can use fputs() to print a prompt, and fgets() to get a response. Then use atoi() or strtol() to parse that string into an unsigned int. You can find these in stdio.h and stdlib.h. Read up on the documentation for those functions to see what would work best for your program.

2) Use pow() from math.h

to calculate that exponent, then printf() to display it. Watch out for integer overflows, unless you're certain that you will never get input that large.

3) fputs(), fgets(), and atoi()/strtol() again.

4) ??? I'm assuming you need to find the circumference and area of a circle with the radius you got in step 3. Just print 2r and r2, #defining pi as a constant (or double) with whatever precision you think necessary.

5) fputs(), fgets(), and atof() to convert the float.

6) That's a one-liner. Just printf("%d", (2 * 3 * x) + (3 * 2 * x) + (4 * x) + 5)

Let me know if you need any more help, but you should be able to get by if you read up on the documentation for each function.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote