C program to find greatest and smallest element in an array - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Sunday, February 2, 2020

C program to find greatest and smallest element in an array - My CS Tutorial


C program to find maximum and minimum number of element in an array.

In this tutorial we will learn how to write a c program code to find greatest and smallest number using an array.

In the first we will enter the range of an array then we will enter the integers according to range.

After it compiler will check and execute the conditions and print the greatest and smallest number.


C PROGRAM CODE


#include<stdio.h>
#include<conio.h>
void main()
{
    int size,x,greatest=0,smallest=0;
    int array[50];
    clrscr();
 
    printf("\n ENTER SIZE OF THIS ARRAY TO FIND GREATEST AND SMALLEST NUMBER:\n ");
    scanf("%d",&size);
 
    printf("\n ENTER THE INTEGERS:\n ");
 
    for(x=0;x<size;x++)
    {
        scanf("%d",&array[x]);
    }
    smallest=array[0];
    greatest=array[0];
    for(x=0;x<size;x++)
    {
        if(array[x]>greatest)
        {
          greatest=array[x];
        }
        if(array[x]<smallest)
        {
            smallest=array[x];
        }
    }
 
    printf("\n THE GREATEST NUMBER IS:\n %d\n",greatest);
 
    printf("\n THE SMALLEST NUMBER IS:\n %d\n",smallest);
 
    getch();
}


OUTPUT:




Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN


No comments:

Post a Comment