# How to print out a specific subscript number?

Page 1 of 1

## 3 Replies - 1080 Views - Last Post: 18 February 2013 - 10:49 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312548&amp;s=282a2cac91322b3ac4f6aa220c74628a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bulldogs2016

Reputation: 0
• Posts: 2
• Joined: 17-February 13

# How to print out a specific subscript number?

Posted 17 February 2013 - 05:54 PM

Okay. I have been searching around this for hours. In my code I need to print out the subscript number of an array.
Example code I found in the book:
[
int main {

const int size = 3;
double arr[size] = {7.8,9.0,6.3}
double largest = arr[0]
for(int i =1; i<size; i++){
if(arr[i] > largest){
largest = arr[i];
}
}
cout << largest << endl;

return 0;
}
]

Now that prints out "8". How can I the print out of "arr[1]" ?

This post has been edited by jimblumberg: 17 February 2013 - 06:22 PM
Reason for edit:: Added missing code tags. Please learn to use them properly.

Is This A Good Question/Topic? 0

## Replies To: How to print out a specific subscript number?

### #2 CTphpnwb

• D.I.C Lover

Reputation: 3390
• Posts: 12,006
• Joined: 08-August 08

## Re: How to print out a specific subscript number?

Posted 17 February 2013 - 06:01 PM

largest = i;

and then
cout << arr[largest] << endl;

### #3 buffalobill

Reputation: 21
• Posts: 188
• Joined: 08-July 08

## Re: How to print out a specific subscript number?

Posted 18 February 2013 - 08:44 PM

Change i=1; to i=0; in the loop. Also you need a ; after 6.3 in the initialization list for array arr[3] and another one at end of line 5,

This post has been edited by buffalobill: 18 February 2013 - 08:45 PM

### #4 bulldogs2016

Reputation: 0
• Posts: 2
• Joined: 17-February 13

## Re: How to print out a specific subscript number?

Posted 18 February 2013 - 10:49 PM

I = 1 because largest already equals arr[0] so there is no point in having the for loop check for arr[0]. This is just an example code that I got from the book. Not code that I am actually using for my project. Any errors were a quick typing mistake.