LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 07-24-2006, 11:25 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...

Last edited by icylicious; 07-24-2006 at 11:40 AM.
 
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
 
  


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 Linux - Newbie 3 07-24-2006 01:25 PM
URGENT: need simple smb live distro Fraudulent Linux - Enterprise 1 04-13-2005 07:09 AM
kernel: ASSERT.... soba Linux - General 1 10-22-2003 06:51 PM
prob setting up ipchains for network(Urgent plse) Brian Workman Linux - Security 3 05-01-2002 03:12 AM
A Simple Prob With Modem Mewizard Linux - Newbie 2 05-18-2001 01:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:14 PM.

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