Unit Test 3 - *area of circle C = PI R = 5 perimeter =...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Unit 3 Readiness Test Version A 1. #define PI 3.14159 main() { int R, C; /*R-Radius of circle */ float perimeter; /*Circumference of circle */ float area; /*area of circle */ C = PI R = 5; Perimeter = 2.0 *C *R; Area = C*R*R; Printf(“%f”, “%d”, &perimeter, &area) } Syntax errors: Did not include <stdio.h> The second line should read int main(void) Does not use Hungarian notation Declares the PI value as an int Does not include a semicolon after “C = PI” “Perimeter” should not be capitalized “Area” should not be capitalized “Printf” should not be capitalized Does not include a semicolon after the printf statement Includes & before variable names when it shouldn’t Omits return(0); statement Includes too many quotation marks inside the printf statement Prints the area as an integer The code should read: #include <stdio.h> #define PI 3.14159 int main(void) { int R; /*R-Radius of circle */ float C; float perimeter; /*Circumference of circle */ float area;
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /*area of circle */ C = PI; R = 5; perimeter = 2.0 *C *R; area = C*R*R; printf("%f, %f",perimeter,area); return(0); } This program will calculate and print the perimeter and area of a circle with radius = 5. 2. #include <stdio.h> #include <math.h> int main(void) { float fDistance1, fDistance2, fDistanceTraveled; float fTime1, fTime2; float fU; float fA; printf(“Please input the first time: ”); scanf(“%f”,&fTime1); printf(“Please input the second time: ”); scanf(“%f”,&fTime2); printf(“Please input the initial velocity: ”); scanf(“%f”,&fU); printf(“Please input the acceleration: ”); scanf(“%f”,&fA); fDistance1=(fU*fTime1)+(0.5*fA*pow(fTime1,2.0)); fDistance2=(fU*fTime2)+(0.5*fA*pow(fTime2,2.0)); fDistanceTraveled = fDistance2-fDistance1; printf(“The distance traveled between the time interval is: %8.3f”,fDistanceTraveled); return(0); } 3. i) 7 ii) 3 iii) 6...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern