source: CIVL/examples/arithmetic/mean.cvl@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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