source:
CIVL/mods/dev.civl.com/examples/contracts/loopInvariants.c@
cb4d4f4
| Last change on this file since cb4d4f4 was aad342c, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 240 bytes | |
| Rev | Line | |
|---|---|---|
| [d257e5e] | 1 | #include <assert.h> |
| 2 | ||
| 3 | $input int n; | |
| 4 | $input int m; | |
| 5 | $assume(n > m && m > 0); | |
| 6 | int main() { | |
| 7 | int i = 0; | |
| 8 | int x = 0; | |
| 9 | ||
| 10 | /*@ loop invariant x * 2 == i * (i + 1); | |
| 11 | */ | |
| 12 | while (i < n) | |
| 13 | x += (i++); | |
| 14 | assert(2 * x == n * (n - 1)); | |
| 15 | return 0; | |
| 16 | } |
Note:
See TracBrowser
for help on using the repository browser.
