Thursday, February 7, 2019

Display Smallest and Largest Elements in an Array - using "C-Language" in Ubuntu.

File Name :largesmall.c

#include<stdio.h>
void main()
{
 int a[50],i,n,s,l;
 printf("Enter size of Array: ");
 scanf("%d",&n);
 printf("Enter %d elements into the Array:\n",n);
 for(i=0;i<n;++i)
     scanf("%d",&a[i]);
 l=s=a[0];
 for(i=1;i<n;++i)
    {
     if(a[i]>l)
        l=a[i];
     if(a[i]<s)
        s=a[i];
    }
 printf("\nThe smallest element is %d\n",s);
 printf("The largest element is %d\n",l);
}

Output:
Enter size of Array: 3                                                                                                                             
Enter 3 elements into the Array:
12                                                                                                                                                 
3                                                                                                                                                 
67                                                                                                                                                 
The smallest element is 3
The largest element is 67

No comments:

Post a Comment

Hadoop Commands

HADOOP COMMANDS OS : Ubuntu Environment Author : Bottu Gurunadha Rao Created: 31-Jan-2022 Updated: 31-Jan-2022 Release  : 1.0.1 Purpose: To ...

Search This Blog