Solved

Help solving a math problem

Posted on 1998-12-10
4
168 Views
Last Modified: 2010-04-15
I am writing a program and part of it I need to:
a number is queried (from 1 - 17)lets call it numb.
i need to generate random numbers in the amount of numb.
ex: if numb is 4 i need to generate four seperate random numbers and add them together.
if someone can show me a easy way to do this it would be appreciated.
P.S. numb will be different everytime the program is run.
0
Comment
Question by:sadorsky
  • 2
4 Comments
 

Author Comment

by:sadorsky
ID: 1255032
Edited text of question
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 1255033
int i=0;
int r=random();
int numb=(r%10)+(r%7)+1;
if(rumb==4)while(i++<5)r+=random();
printf("%d:%d",numb, r);
0
 
LVL 10

Expert Comment

by:rbr
ID: 1255034
try this

unsigned long randomadd(int numb)
{
unsigned long together;
int i;

together=0;

for (i=0;i<numb;i++)
      together += rand();
return (together);
}
0
 

Author Comment

by:sadorsky
ID: 1255035
Thanks I'll give it a try ...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I avoid pointer to integer casting errors in C programming? 4 225
Socket Programming (Unix) 8 125
Digital Output does not have continuity to ground? 3 90
Line meaning 9 85
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question