Success For All Reading Program

success for all reading program
Finding Biggest Value in array (C Programming)?

I have integer data in data.dat. Assume the data b[19] = {1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1}. Then I write the program to read the data from the file. Success! but, I can’t find the biggest value. This is the part of finding the biggest value:

a=0 /*init value of a = 0 so it can check the value below*/
for(i=0;i<19;i++) /*20 data in the array of b*/
{
if(a>b[i]){ /*check the condition*/
printf(“This is the biggest value: %dn”,a)
}
a = b[i]; /*store the current value of b to a so it can check in the next loop*/
}

but i get back these result:

This is the biggest value: 10
This is the biggest value: 9
This is the biggest value: 8
This is the biggest value: 7
This is the biggest value: 6
This is the biggest value: 5
This is the biggest value: 4
This is the biggest value: 3
This is the biggest value: 2

I know the problem: it only check the value before not all.

Please help me…..

oSourceM has put it wrong.. SOrry mate!!

but the right code wud go like this….

big = b[0];
for (i=0;i<=19;i++)
{
if (big big=b[i];
}
printf("biggest value = %dn",big);

the variable big contains the largest value in the array...

if the array consist n elements...

big = b[0];
for (i=0;i<=n;i++)
{
if (big big=b[i];
}

Enjoy!! I hope you got what you needed.....

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • StumbleUpon
  • Twitter
  • Yahoo! Bookmarks
You can leave a response, or trackback from your own site.

Leave a Reply

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars