bad: help me urgent just simple assert.h prob
bad: help me urgent just simple assert.h prob
--------------------------------------------------------------------------------
#include<assert.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main (void)
{
int a, b, cnt=0, i;
for(i=0; i <1000; ++i){
a= rand() % 3 + 1;
b= rand() % 30 + 1;
if (b - a <= 1)
continue;
assert (b - a > 2);
printf("count=%d\n", ++cnt);
}
return 0;
}
that's the program and i cant understand how it works. i tried running the program and get different count results with two different computer i used. i tried researching about the functions time.h ; rand() and assert.h using the book A Book on C where this exercise can be found but no vivid explanation on how this works. i tried changing the values of %30 to % 20 and %10. i get different count results but i found no logic on it.please help me answer these questions too, 1.what values of a and b cause the assertion to fail? i think its 2 and 4, 3 and 5, 3 and 4. is this right? 2. how many times do u expect to go through the loop? number of times the program is executed? and the number of iterations produced per execution of the program? i dont know how this programs really works so i don't know how to track the number of times
guys please help me thanks...
Last edited by icylicious; 07-24-2006 at 11:40 AM.
|