0

1.How we can intialise all the elements of the array to -1.

2.Randomly generate and store the age of N studnets .

3.sort and display the array in ascending order .

thnks :-)

Not Yet Answered # Array in C++

Ancient Dragon 5,243 Discussion Starter alex k Ancient Dragon 5,243 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

1.How we can intialise all the elements of the array to -1.

2.Randomly generate and store the age of N studnets .

3.sort and display the array in ascending order .

thnks :-)

0

1. use a loop

2. call `srand( (unsigned int)time(0));`

to initialize the random number generator, then for each number call `rand()`

to get a random number.

3. google for sort algorithms. The bubble sort is the easiest to code but the slowest. In c++ you can also use the std::sort() method found in <algorithm> header file.

0

thnks Ancient Dragon :-)

i did this ..wat do u think?

```
srand( time(0) ); //seed random number generator
int age[3] = { 18 , 40, 65 };
int randomage = rand() % 3; //return a number from [18,75)
```

now if i want to calculate the avearge of students age..is that right?

```
Int Sum = 0;
for( int i = 18; i < 75; i++)
{
Sum = Sum + array[i];
}
```

I found this context about the sort algorthim

```
void selectionSort ( int arr[], int size )
{
int indexOfMin;
int pass;
int j;
for ( pass = 0; pass < size - 1; pass++ )
{
indexOfMin = pass;
for ( j = pass + 1; j < size; j++ )
if ( arr[j] < arr[pass] )
indexOfMin = j;
swap ( arr[pass], arr[indexOfMin] );
}
}
// swap function for integers
void swap ( int& x, int& y )
{
int temp;
temp = x;
x = y;
y = temp;
}
void sort()
{
int size=57;
int j,temp,i;
for(i=0;i<(size-1);i++)
{
for(j=i+1;j<size;j++)
{
if(queue[i]>queue[j])
{
temp=queue[i];
queue[i]=queue[j];
queue[j]=temp;
}
}
}
cout<<"Status: sorting done."<<endl
```

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting

0

>>int age[3] = { 18 , 40, 65 };

Why are you initializing it with some dummy data? Just initialise the array with all 0s `int age[3] = {0};`

>>int randomage = rand() % 3; //return a number from [18,75)

That's a number between 0 and 3, not 18 and 75

>>for( int i = 18; i < 75; i++)

The array only has 3 elements. You are trying to use the age range as the index into the array. What you want is this: `for(int i = 0; i < 3; i++)`

*Edited 6 Years Ago by Ancient Dragon*: n/a

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...