This program illustrates the concept of One-Dimensional Array. In this
program some elements are taken in array and maximum and minimum element
are found out. Complete source code and Output is given here..
Source Code
Output
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| //finding the maximum and minimum element of array #include<stdio.h> int findmax( int array[], int n){ int i, maximum; maximum = array[0]; for (i = 0; i < n; i++){ if (maximum < array[i]) maximum = array[i]; } return maximum; } int findmin( int array[], int n){ int i, minimum; minimum = array[0]; for (i = 0; i < n; i++){ if (minimum > array[i]) minimum = array[i]; } return minimum; } int main(){ int array[10]; //array declaration of maximum size 10 int max,min,n,i; printf ( "Enter the no of element: " ); scanf ( "%d" ,&n); printf ( "Enter the array: " ); for (i = 0; i < n; i++){ scanf ( "%d" ,&array[i]); } max = findmax(array, n); min = findmin(array, n); printf ( "\nThe maximum element is %d" , max); printf ( "\nThe minimum element is %d\n\n" , min); return 0; } |
No comments:
Post a Comment
Comment