sana.pari
04-24-2011, 04:42 PM
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
#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();
}
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
#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();
}