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 DocumentRight 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 &lt;stdio.h&gt; #include &lt;math.h&gt; #include &quot;header1.h&quot; #include &quot;header2.h&quot; int main(void) { int iN; printf(&quot;Input an integer value: &quot;); scanf(&quot;%d&quot;,&amp;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&lt;=iN;i++) { iSum += pow(-1,i+1)*((2*i)-1); } printf(&quot;The sum of the series is %d\n&quot;,iSum); return iSum; } // header2.h: void divisible(int); void divisible(int iSum) { if (iSum%5==0) printf(&quot;The sum is divisible by 5&quot;); else printf(&quot;The sum is not divisible by 5&quot;); }...
View Full Document

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