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

Info iconThis 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; } 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 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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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

This note was uploaded on 03/19/2008 for the course ME 205 taught by Professor Koen during the Spring '07 term at University of Texas.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online