Sponsored Links


Results 1 to 2 of 2

Thread: PROBLOM IN PROGRAMMING code 2011

  1. #1
    sana.pari
    Guest

    Icon14 PROBLOM IN PROGRAMMING code 2011

    Sponsored Links1


    RESPECTED SIR THIS PROGRAM IS CODED IN OUR TEXT BOOK
    SIR I HAD DONE THIS EXAMPLE AND TJIS EXAMPLE RUN SUCCESSFULLY
    SIR ONE QUESTION RISES IN MINE MIND THAT WE HAVE DECLARED
    THE SIZE OF ARRAY IS GIVEN AS 7 IT MEANS THAT ONLY SEVEN
    VALUES CAN BE STORED BUT HERE WE HAD STORED ALL THE VALUES
    OF THE NUMBERS GENERATED BY THE RAND FUNCTION

    HOW DOES IT HAPPENED KINDLY TELL ME THAT WHAT DOES THIS
    LOOP IS DOING
    for (roll=1;roll<=600000;roll++)
    frequency[1+rand()%6]++;
    THE CODE IS SNIPPED THERE

    Sponsored Links

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<iomanip.h>
    using std::setw;
    #include<cstdlib>
    using std::rand;
    using std::srand;
    #include<ctime>
    using std::time;
    main()
    {
     int roll;
     int face;
     const int arraysize=7;
     int frequency[arraysize]={};
     for (roll=1;roll<=600000;roll++)
     frequency[1+rand()%6]++;
     cout<<"FACE";
     cout<<setw(13);
     cout<<"FREQUENCY";
     cout<<endl;
     for ( face=1;face<arraysize;face++)
     {
      cout<<setw(4);
      cout<<face;
      cout<<setw(13);
      cout<<frequency[face];
      cout<<endl;
    }
    cout<<getch();
    }

  2. #2
    Dear Student,
    This program is just like a game where a Die is rolled. We know that a Die consists of 6 numbers from 1 to 6 on its each different face. Here in this program, the objective is to find the number of times each face will come up when that die is rolled 600000 times. Let us look at the logic behind the loop which you are finding dificult to understand.

    Code:
    for (roll=1;roll<=600000;roll++) 
        frequency[1+rand()%6]++;

    In the loop declaration, you can see that loop limit is less than equal to 600000, which means that this loop will be executed 600000 times. In other words, this limits describes the number of times the Die will be rolled. Now lets come to second statement of the above code. We know that a die can only have 6 faces. when the 1+rand()%6 is executed, it always returns a value less than or equal to 6 becuase this value will represent the value of each face of the die.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 02-13-2013, 08:19 PM
  2. c++ code check this code 2011-12
    By Vuhelper in forum C++ Programing
    Replies: 0
    Last Post: 09-04-2011, 07:17 AM
  3. c++ code 2011
    By saneha in forum C++ Programing
    Replies: 0
    Last Post: 05-02-2011, 05:45 PM
  4. c++ code 2011
    By saneha in forum C++ Programing
    Replies: 0
    Last Post: 04-29-2011, 08:27 AM
  5. Replies: 1
    Last Post: 04-24-2011, 05:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft