Thursday, July 9, 2009

C Programming: Write a program that generates a random number from the following set: 1, 4, 7, 10, 13, 16?

copy paste this function and call it at will!


#include%26lt;stdlib.h%26gt;





int ran()


{


int arr[5];


arr[0]=1;


arr[1]=4;


arr[2]=7;


arr[3]=10;


arr[4]=13;


arr[5]=16;


int t=random(5);


return arr[t];





Hope this helps!

C Programming: Write a program that generates a random number from the following set: 1, 4, 7, 10, 13, 16?
Put those numbers into an array.





Then generate a random number from 0 to 5.





Then call the number in that item of the array.





That's it, that's all, it's as simple as that.

quince

No comments:

Post a Comment