Sum

+1 Benjamin Niedland · August 10, 2015
How do i get the sum of randomly generated numbers in C 

Post a Reply

Replies

Oldest  Newest  Rating
0 Franz Schmidt · August 10, 2015
I would reccomand to do a function if you allready learnd how to do it:

int add(int num1, int num2){
  return num1 + num2;
}

this function will return you the sum of whatever number you enter for num1 and num2 as parameters
so in you main function you need to do get 2 numbers, wheather by user input (scanf) or random generation (rand) and pass them to the function as parameter:

int main(){
  ...
  sum = add(input1, input2);
...
}
0 Sha Kal · August 10, 2015
If you however don't know how to do function:

rNum = rand () ....

Then you print rNum instead of rand()...

and at the end of your loop just add rNum to the total value.
  • 1

C

107,275 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator