EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

Write a program to find the largest and smallest number in the given array using functions

Source Code

#include<stdio.h>
#include<conio.h>
int islargest(int ar[100],int n)
{
  int i,l,t=0;
  l=ar[0];
  for(i=1;i<n;i++)
  {
         if(l<ar[i])
10           {
11           t=l;
12           l=ar[i];
13           ar[i]=t;
14           }
15    }
16    return l;
17  }
18  int issmallest(int ar[100],int n)
19  {
20    int i,s,t=0;
21    s=ar[0];
22    for(i=1;i<n;i++)
23    {
24           if(s>ar[i])
25           {
26           t=s;
27           s=ar[i];
28           ar[i]=t;
29           }
30    }
31    return s;
32  }
33  int main (int argc, char *argv[])
34  {
35    clrscr();
36    int ar[100];
37    int i,s,lar,sml;
38    for(i=0;i<100;i++)
39    {
40      ar[i]=0;
41    }
42    printf("\nEnter the siize of the array:");
43    scanf("%d",&s);
44    printf("\nEnter the elements of the array:");
45    for(i=0;i<s;i++)
46    {
47      printf("\nEnter element number: %d ",(i+1));
48      scanf("%d",&ar[i]);
49    }
50    lar=islargest(ar,s);
51    sml=issmallest(ar,s);
52    printf("\nThe largest and smallest elements in the array are: %d and %d",lar,sml);
53    getch();
54  }

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code