Simple solution to find largest & smallest number in array.

Discussion in 'C' started by kabirk007, Jan 27, 2009.

Thread Status:
Not open for further replies.
  1. kabirk007

    kabirk007 New Member

    Joined:
    Dec 2, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a[10],n,i,large,small;
    printf("enter the value of n\n");
    scanf("%d",&n);
    printf("enter the numbers\n");
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    large=a[0];
    small=a[0];
    for(i=1;i<n;i++)
    {
    if(a[i]>large)
    large=a[i];
    if(a[i]<small);
    small=a[i];}
    printf("The largest number is %d\n",large);
    printf("smallest number is %d\n",small);
    getch();
    }
     
    Last edited by a moderator: Jan 27, 2009
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice