• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please explain how does this program works?(arrays)  RSS feed

 
beu curt
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI!


So this program find out which is the largest among 10 inputted numbers.
Can you please stimulate how this program works.
What if I input numbers from 3-12? How will this program work that out?
How would you explain it to a beginner?


Thank you
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
# if((counter == 0)|| (num[counter]>max))
# max= num[counter];

Here is its heart. suppose you enre numbers 4,5,8,6,9,7,8,33,7,9
First time counter == 0 so max is 4
Second time counter == 0 is false, so it goes for next condition num[counter]>max) i.e. 5>4.. YES. so make max= 5

program proceeds same way and prints maximum value at the end.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!