Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Help solving a math problem

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
sadorsky
Asked:
sadorsky
  • 2
1 Solution
 
sadorskyAuthor Commented:
Edited text of question
0
 
ahoffmannCommented:
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
 
rbrCommented:
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
 
sadorskyAuthor Commented:
Thanks I'll give it a try ...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now