source: CIVL/examples/contracts/contractsSeq/sum.c

main
Last change on this file 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: 585 bytes
RevLine 
[9aaed1f]1#include<assert.h>
2#include<stdio.h>
3/*@
4 @ ensures \result == x + y;
5*/
6int add(int x, int y){
7 return x + y;
8}
9
10/*@ requires n >= 8 && n <= 10;
[fb1d9d13]11 @ ensures ((n + 1) * n) == \result * 2;
[9aaed1f]12 */
13int sum1(int n) {
14 int ret = 0;
15
16 for(int i = 0; i <= n; i++) {
17 printf("%d\n",i);
18 ret = add(ret, i);
19 }
20 return ret;
21}
22
23/*@ requires n >= 0;
[fb1d9d13]24 @ ensures ((n + 1) * n) == \result * 2;
[9aaed1f]25 */
26int sum2(int n) {
27 int ret = 0;
28 int arg;
29
30 if(n <= 0) return 0;
31 else{
32 arg = sum2(n - 1);
33 ret = add(n, arg);
34 }
35 return ret;
36}
37
38int main() {
39 add(0,0);
40 sum1(0);
41 sum2(0);
42}
Note: See TracBrowser for help on using the repository browser.