CSE 1320 Assignment 1 solved

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (7 votes)

1. (20%) What is the output of the following code? #include int main(void) { int a = 1; int b = 2; printf(“a / b is %d\n”, a / b); return 0; } Put your answer in a file named answer1.txt. 2. (20%) Fix the following program such that it properly calculated 5 / 3. #include int main() { float a = 5 / 3; printf(“Shouldn’t %f be a floating point?”, a); return 0; } Save the fixed program as float_fix.c. 3. (20%) Create a program that calculates the volume of a sphere. It should prompt the user to enter the radius and calculate the volume based on their input. (a) The resulting volume should be truncated to two decimal places. (b) Use the preprocessor directive #define PI 3.14159 as your definition of π. (c) The control string for the input prompt should be “ENTER RADIUS: “. (d) The volume of a sphere is 4 3 πr3 Example Run ENTER RADIUS: 3.4 The volume of a sphere with radius 3.400000 is 164.64 CSE 1320: Assignment 1 Dillhoff Save your code as sphere_volume.c. 4. (20%) Create a program that accepts 5 sequential integer inputs from the user and counts the number of even and odd numbers that the user entered. (a) You should not use any control statements (if, else, switch, etc.) (b) You may only use one variable total to count the number of even and odd integers. (c) The format of your output should be “Even: %d, Odd: %d” Example Run 2 4 5 6 7 Even: 3, Odd: 2 Save your code as evenodd.c. 5. (20%) Create a program is able to calculate the area, volume, or circumference of a sphere depending on user input. (a) The resulting calculations should be truncated to two decimal places. (b) Use the preprocessor directive #define PI 3.14159 as your definition of π. (c) The program should accept two inputs, a formula choice and a radius value. Use v for volume, a for area, and c for circumference. (d) Any other initial input besides ’v’, ’a’, or ’c’ should inform the user that their input is invalid. (e) The input prompt is >. (f) The output should reflect the user’s choice (see example run). (g) The volume of a sphere is 4 3 πr3 (h) The area of a sphere is 4πr2 (i) The circumference of a sphere is 2πr Example Run > a 1.2 The area is 18.10 > t 6 Invalid input. Save your code as sphere_formulas.c. Create a zip file using the name template _.zip which includes the all required code and answer files. Submit the zip file through Canvas. 2