Showing posts with label Program to find the maximum and minimum value in an array. Show all posts
Showing posts with label Program to find the maximum and minimum value in an array. Show all posts

Wednesday, July 20, 2011

Program to find the maximum and minimum value in an array

/*Serial No.83     [swami57.cpp]*/

#include<stdio.h>
#include<conio.h>
void main()
    {
    int k;
    int a[5],i,j,max=0,min=0;
    printf("Enter how many numbers in array:=");
    scanf("%d",&k);
    printf("enter the numbers:\n");
    for(i=0;i<k;i++)
        {
        scanf("%d",&a[i]);
        }
        max=a[0];
        min=a[0];
        for(i=1;i<k;i++)
            {
            if(a[i]>max)
            {
            max=a[i];
            }
            if(a[i]<min)
            {
            min=a[i];
            }
            }
    printf("Maximum value of array:=%d\n",max);
    printf("Minimum value of array:=%d",min);
    getch();
    }