Unit Test 6 - float equation2(float fInput float fAns =...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Unit 6 Readiness Test Version B 1) This program will print: first 1 2 5 second 7 2.0 6 third 7 2 5 2) #include <stdio.h> #include "header1.h" #include "header2.h" #include "header3.h" int main(void) { float fX = getfX(); equation1(fX); equation2(fX); if (equation1(fX)>equation2(fX)) printf("The first equation returns a larger value: %6.4f",equation1(fX)); else printf("The second equation returns a larger value: %6.4f",equation2(fX)); return(0); } // header1.h: float getfX(); float getfX(void) { float fX; printf("Input a value for x: "); scanf("%f",&fX); return(fX); } // header2.h: float equation1(float); float equation1(float fInput) { float fAns = (fInput*fInput)-fInput; return(fAns);
Background image of page 1

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

View Full Document Right Arrow Icon
} // header3.h: float equation2(float);
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: float equation2(float fInput) { float fAns = fInput+5; return(fAns); } 3) #include <stdio.h> #include <math.h> #include "header1.h" #include "header2.h" int main(void) { int iN; printf("Input an integer value: "); scanf("%d",&iN); int iSum = summation(iN); divisible(iSum); return(0); } // header1.h: int summation(int); int summation(int iN) { int iSum = 0; for (int i = 1;i<=iN;i++) { iSum += pow(-1,i+1)*((2*i)-1); } printf("The sum of the series is %d\n",iSum); return iSum; } // header2.h: void divisible(int); void divisible(int iSum) { if (iSum%5==0) printf("The sum is divisible by 5"); else printf("The sum is not divisible by 5"); }...
View Full Document

{[ snackBarMessage ]}

Page1 / 3

Unit Test 6 - float equation2(float fInput float fAns =...

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

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