Solved

Help solving a math problem

Posted on 1998-12-10
4
165 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now