source: CIVL/examples/arithmetic/mean.cvl

main
Last change on this file was b689afd, checked in by Stephen Siegel <siegel@…>, 4 weeks ago

Getting rid of unused examples that are not good and starting to clean
up others.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@6036 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 510 bytes
RevLine 
[89b55f5]1/* Commandline execution:
2 * civl verify -inputB=10 mean.cvl
3 */
[0baeebd]4$input int B = 10;
[b96205d]5$input int n;
[3ff27cf]6$assume(1<=n && n<=B);
[b96205d]7$input double a[n];
[8fa5a7b]8double s;
9
10void main() {
[b96205d]11 double mean1() {
12 double sum=0.0;
13
14 for (int i=0; i<n; i++)
15 sum += a[i];
16 return sum/n;
17 }
18 double mean2() {
19 double result=a[0];
[8fa5a7b]20
[b96205d]21 for (int i=1; i<n; i++)
22 result = result*(i*1.0/(i+1)) + a[i]/(i+1);
23 return result;
24 }
25 double result1 = mean1();
26 double result2 = mean2();
[d980649]27 $assert(result1==result2);
[b96205d]28}
Note: See TracBrowser for help on using the repository browser.