• Post Reply Bookmark Topic Watch Topic
  • New Topic

Index of a Largest Number in a Integer  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

This is my program



and this is my output

Enter the Total Number of Integers:
5
Enter Integer-1:
12
Enter Integer-2:
123
Enter Integer-3:
120
Enter Integer-4:
11
Enter Integer-5:
3
Largest Number is:123


I want to get Index of that particular number in which Value is largest.


What I need to change in my program?


Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:
I want to get Index of that particular number in which Value is largest.


What I need to change in my program?


Your code already saves the largest integer that it finds. You just need to change it to save the loop index at the same time.

Henry
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to save that Index?

give a example using code

Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:How to save that Index?

give a example using code


How about using your own program as an example? How are you currently saving the largest integer? Why can't you do the same thing -- just with different variables?

Henry
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:How to save that Index?
give a example using code

Here is an example where the largest value is saved:


Now see if you can modify it so that it ADDITIONALLY saves the index.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all

With a little editing I saved largest Index


Thanks
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the minus in Enter Integer because it makes your printout look like all negative numbers.

And well done sorting it out.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK thanks I have changed - sign
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something else to consider:


What do you think this line is doing?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this line will retain previous value of largest in that variable.

I mean its like reassigning value to that variable


does it make any problem?

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:this line will retain previous value of largest in that variable.


Or in other words, it does absolutely nothing. BTW, can you think of a more efficient way of doing absolutely nothing? ...

Henry
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry and fred

I removed that Line from my code

Its Working fine
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!