Tuesday, 5 February 2013

Write a c program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array



#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[10],i,n,max,min;
  clrscr();
  printf("\nEnter the n numbers: ");
  scanf("%d",&n);
  printf("\nEnter  the numbers: ");
  for(i=0;i<n;i++)
{
  scanf("%d",&a[i]);
}
  max=a[0];
  min=a[0];
  for(i=0;i<n;i++)
{
  if(a[i]>max)
{
  max=a[i];
}
  if(a[i]<min)
{
  min=a[i];
}
}
  printf("\nMaximum number is:%d",max);
  printf("\nMinimum number is:%d",min);
  getch();
}

//OUTPUT:
//Enter the n numbers: 4
//Enter the numbers: 1 2 3 4
//Maximum number is:4
//Minimum number is:1

No comments:

Post a Comment