Friday, 22 March 2019

CP: Find maximum and minimum value from array

Que: 
Write a program to accept 5 numbers in an array and find the maximum and minimum value of it.

Code: 

#include <stdio.h>

void  main()

{
    int a[5],i,small,max;
    printf("enter any 5 value\n");

    for(i=0; i<5; i++)
    {
        scanf("%d", &a[i]);
    }

    small=a[0];

    for(i=1;i<5;i++)

        if (a[i]<small)
        {
            small=a[i];
        }

    max=a[0];

    for(i=1;i<=5;i++)

        if (a[i]>max)
        {
            max=a[i];
        }

        printf("small value is =%d \n",small);
        printf("maximum value is =%d ",max);


}

Output:



No comments:

Post a Comment

LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project

  LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project Dear All We will learn how to Connec...