LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > LinuxQuestions.org > LinuxQuestions.org Member Intro
User Name
Password
LinuxQuestions.org Member Intro New to LinuxQuestions.org? Been a long time member but never made a post? Introduce yourself here.

Notices


Closed Thread
  Search this Thread
Old 07-24-2006, 11:45 AM   #1
icylicious
LQ Newbie
 
Registered: Jul 2006
Posts: 12

Rep: Reputation: 0
Question 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...
 
Old 07-24-2006, 01:18 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php
 
Old 07-24-2006, 02:50 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Thread closed. Please post all replies to http://www.linuxquestions.org/questi...d.php?t=467142
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bad: help me urgent just simple assert.h prob icylicious Programming 11 07-24-2006 02:53 PM
bad: help me urgent just simple assert.h prob icylicious Linux - Newbie 3 07-24-2006 01:25 PM
bad: help me urgent just simple assert.h prob icylicious Programming 1 07-24-2006 01:18 PM

LinuxQuestions.org > Forums > LinuxQuestions.org > LinuxQuestions.org Member Intro

All times are GMT -5. The time now is 04:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration