473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

random_number

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <cstdlib>
  4. #include "random.h" 
  5. #include "random1.h" 
  6. #define pi 3.1415926535
  7.  
  8. int main(int argc, char *argv[])
  9.     {     
  10. int  k , n , i ;                                                                                                                                                   /* for (k=1;k<12;k++){Random();printf("random=%.2f\n",Random());}for(k=1;k<12;k++){Random1();printf("random1=%.2f\n",Random1());}*/                                      
  11.   for ( k=1 ; k<=12 ; k++ )
  12.               {
  13.               double   *U1                     ;
  14.               double valoare                   ;    
  15.               Random()                         ;
  16.               valoare= Random()                ; 
  17.           //    printf("random=%.2f\n",valoare);      
  18.            //   printf("valoare=%.2f\n",valoare) ;
  19.               U1[k]=valoare                    ;   
  20.               printf("U1[%d]=%.2f\n",k, U1[k]) ; 
  21.  
  22.               }       
  23. for ( k=1 ; k<=12 ; k++ )
  24.               {
  25.               double  *U2                      ;
  26.               double valoare1                  ;
  27.               Random1();               
  28.               valoare1= Random1()              ;    
  29.           //     printf("random1=%.2f\n",valoare1);
  30.               U2[k]=valoare1                   ;
  31.               printf("U2[%d]=%.2f\n",k,U2[k])  ;
  32.               }
  33.  
  34.  
  35.  
  36.  
  37.  
  38. for(k=1;k<=12;k++)   
  39.       {   
  40.           double   *R , *M , *Z1 , *Z2 , *U1 , *U2       ;
  41.  
  42.  
  43.       R[k]    = sqrt(-2*log(U1[k]))     ;
  44.       printf("random4=%.2f\n",R[k])     ;
  45.       M[k]    = 2*pi*U2[k]              ;
  46.       Z1[k]   = R[k]*cos(M[k])          ;
  47.       Z2[k]   = R[k]*sin(M[k])          ;  
  48.       double  *random_normal            ;
  49.       random_normal[k]= Z1[k]           ;
  50.       printf(" random_normal[k]=%.3f\n",random_normal[k] ); 
  51.       } 
  52. system("PAUSE");  
  53. }
  54.  

i have this . the problem is that the third for , U1 and U2 can't be read .
What can i do ?
Jun 1 '07 #1
3 1425
weaknessforcats
9,208 Expert Mod 8TB
You have all these pointers:

double *R , *M , *Z1 , *Z2 , *U1 , *U2 ;


that you are using as arrays but I see no memory allocated for the arrays.

Also, the code is very unreadable. Try to use only one statement per line of code.

Also, use code tags when submitting a code sample
Jun 1 '07 #2
AdrianH
1,251 Expert 1GB
math.h usually has M_PI in it. If it doesn't, try using atan(1)*4 if you want an accurate value.


Adrian
Jun 1 '07 #3
i resolve it , thx .
Jun 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Divvy Bollocks | last post by:
// A big 7 and three-quarters size "Hello" to all C++ programmers out there. This here is the second program what I've // ever wrote, the first being a "Fuck off world you cunt" program. It's a...
0
by: Divvy Bollocks | last post by:
// A big 7 and three-quarters size "Hello" to all C++ programmers out there. This here is the second program what I've // ever wrote, the first being a "Fuck off world you cunt" program. It's a nice...
0
by: Divvy Bollocks | last post by:
// A big 7 and three-quarters size "Hello" to all C++ programmers out there. This here is the second program what I've // ever wrote, the first being a "Fuck off world you cunt" program. It's a nice...
13
by: rhitx | last post by:
Hello: I'm trying create a random number generator, which will generate either number 1, 2, 3. I tried to do it like: int random_number() { int no_goal, rand_Number;
2
tpgames
by: tpgames | last post by:
Me memory game freezes after I click some cards. I seems to be random as to the number of clicks needed before it freezes. I posted the entire code, as I am not sure what is needed for help. I am...
2
by: hollandlucas | last post by:
Hello, the following script (it's in German): import random print "Wie oft wollen Sie spielen?" anzahl_spiele = input() games = 0 while games < anzahl_spiele: games += 1
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
16
by: sotirac | last post by:
Wondering if there is a better way to generate string of numbers with a length of 5 which also can have a 0 in the front of the number. <pre> random_number = random.sample(, 5) # choose 5...
24
by: Joe, G.I. | last post by:
Hi all, I'm trying to generate about 50 numbers as milliseconds between 0 and 4 seconds and it's driving me crazy. Can anyone help out on how to do this? Any help much appreciated.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.