LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


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

Rep: Reputation: 0
Question 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:38 AM.
 
Old 07-24-2006, 11:25 AM   #2
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
Quote:
Originally Posted by LQ RUles
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
See above.

You have provided no information on what you have done to try and solve the problem yourself before you want people to do it for you
 
Old 07-24-2006, 01:17 PM   #3
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, 01:25 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Per unspawns comment I'm closing this one. Programming to me seems the
most reasonable spot, please take FUPS there.

http://www.linuxquestions.org/questi...17#post2348317
 
  


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
URGENT: need simple smb live distro Fraudulent Linux - Enterprise 1 04-13-2005 07:09 AM
internet randomly shut off on red hat 9 *prob simple fix* alimharji Linux - Wireless Networking 0 04-14-2004 09:16 PM
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 > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:25 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