LinuxQuestions.org
Visit Jeremy's Blog.
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, 12:21 PM   #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 12:38 PM.
 
Old 07-24-2006, 12:25 PM   #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, 02:17 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
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:25 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:09 AM
internet randomly shut off on red hat 9 *prob simple fix* alimharji Linux - Wireless Networking 0 04-14-2004 10:16 PM
kernel: ASSERT.... soba Linux - General 1 10-22-2003 07:51 PM
prob setting up ipchains for network(Urgent plse) Brian Workman Linux - Security 3 05-01-2002 04:12 AM
A Simple Prob With Modem Mewizard Linux - Newbie 2 05-18-2001 02:13 PM


All times are GMT -5. The time now is 07:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration