User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 429,761 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,910 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums

Problem in finding the greatest no. from array

Join Date: Aug 2007
Posts: 20
Reputation: web_master is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
web_master web_master is offline Offline
Newbie Poster

Re: Problem in finding the greatest no. from array

  #4  
May 9th, 2008
I solved it myself......

the code is:
#include<stdio.h>
int main()
{
    int i ,j ,a[5];
    for(i=0;i<=4;i++)
    {
        printf("\n\tEnter the %dst value of the array: ", i+1);
        scanf("%d", &a[i]);
    }
    j = a[0];
    printf("\n\tOriginal array entered by the user: ");
    for(i=0;i<=3;i++)
    {
        printf(" %d ", a[i]);
        if(a[i]<a[i+1])
        {
             j = a[i+1];
        }
    }
    printf("\n\n\tGreatest no. from the array: %d", j);
getch();
return 0;
}

the loop that was comparing the numbers was looping one extra time so i limited it to 4 times (i<=3) instead of 5(i.e. the array size).....

now it works fine......

and i dont see a better way of doing it......maybe there is a easier way.......
Reply With Quote  
All times are GMT -4. The time now is 3:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC