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
|
| Line | |
|---|
| 1 | #include<assert.h>
|
|---|
| 2 | #include<stdio.h>
|
|---|
| 3 | /*@
|
|---|
| 4 | @ ensures \result == x + y;
|
|---|
| 5 | */
|
|---|
| 6 | int add(int x, int y){
|
|---|
| 7 | return x + y;
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | /*@ requires n >= 8 && n <= 10;
|
|---|
| 11 | @ ensures ((n + 1) * n) == \result * 2;
|
|---|
| 12 | */
|
|---|
| 13 | int 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;
|
|---|
| 24 | @ ensures ((n + 1) * n) == \result * 2;
|
|---|
| 25 | */
|
|---|
| 26 | int 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 |
|
|---|
| 38 | int main() {
|
|---|
| 39 | add(0,0);
|
|---|
| 40 | sum1(0);
|
|---|
| 41 | sum2(0);
|
|---|
| 42 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.