C PROGRAM TO FIND LARGEST AND SMALLEST NUMBER IN AN ARRAY
/*PROGRAM BY LAXMAN POUDEL*/ WAP in c to find the largest and smallest numbers using array
#include<stdio.h> #define MAX 25 //maximum size of array is 25 main() { int i,n,LargeNo,SmallNo,arr[MAX]; printf(" ***PROGRAMMING SEEKERS BLOG ***"); printf("\n >>> Program to find Largest element in array <<<"); printf("\n\n Enter the size of array: "); scanf("%d",&n); //taking size of array as input from user printf("\n Enter the %d elements of array: \n",n); //taking input all the elements of array using for loop for(i=0;i<n;i++) { printf("\n arr[%d]:",i+1); scanf("%d",&arr[i]); } LargeNo = arr[0]; SmallNo = arr[0]; for(i=0;i<n;i++) { //checking for Largest Number if(arr[i]>LargeNo) { LargeNo = arr[i]; } //checking for Smallest Number if(arr[i]<SmallNo) { SmallNo = arr[i]; } } //printing the largest and Smallst elements in array printf("\n The Largest Element in the Array is: %d ",LargeNo); printf("\n The Smallest Element in the Array is: %d ",SmallNo); getch(); }
OUTPUT OF THE PROGRAM
Friday, February 3, 2017
Labels:
cprogramming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment