Find the answer to your Linux question:
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 ...
  1. #1
    Just 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 );
    }

    ~

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Use a cast in the expression of the second argument of the printf function:

    Code:
    printf("&#37;s\n %f\n", header, (float)count/ M * 4.0 );
    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...