Results 1 to 2 of 2
I have written a small program there is no error but i get the same header value for different seed numbers can anyone help me with this
#include <stdio.h>
#include ...
- 09-19-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 2
problem in excecution
I have written a small program there is no error but i get the same header value for different seed numbers can anyone help me with this
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
main(int argc, char **argv)
{
const int M = 20000;
char header[20];
int i, count=0;
double x,y;
int seed =319;
if (argc < 2 )
printf("use default seed value %d\n",seed);
else
seed = atoi(argv[1]);
srand48(seed);
for(i=0; i<M; i++ ) {
x= drand48();
y= drand48();
if(x*x+y*y < 1)
count++;
}
strcpy(header, "CIS 620 Sec. 50 Homework 1 Fall 2007") ;
printf("%s\n %f\n", header, count/ M * 4.0 );
}
~
- 09-21-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Use a cast in the expression of the second argument of the printf function:
RegardsCode:printf("%s\n %f\n", header, (float)count/ M * 4.0 );


Reply With Quote