C Program for Largest Integer |
||
1 | #include <stdio.h> | |
2 | int main() | |
3 | { | |
4 | int array[100], maximum, size, c, location = 1; | |
5 | printf("Enter the number_of_elements in_array\n"); | |
6 | scanf("%d", &size); | |
7 | printf("Enter %d integers\n", size); | |
8 | for (c = 0; c < size; c++) | |
9 | scanf("%d", &array[c]); | |
10 | maximum = array[0]; | |
11 | for (c = 1; c < size; c++) | |
12 | { | |
13 | if (array[c] > maximum) | |
14 | { | |
15 | maximum = array[c]; | |
16 | location = c+1; | |
17 | } | |
18 | } | |
19 | printf("Maximum_element is present_at_location %d and it's value is %d.\n", location, maximum); | |
20 | return 0; | |
21 | } |
Largest Integer C Program code by Using Pointers
1 | #include <stdio.h> | ||||
2 | int main() | ||||
3 | { | ||||
4 | long array[100], *maximum, size, c, location = 1; | ||||
5 | printf("Enter the_number_of_elements in array\n"); | ||||
6 | scanf("%ld", &size); | ||||
7 | printf("Enter %ld integers\n", size); | ||||
8 | for ( c = 0 ; c < size ; c++ ) | ||||
9 | scanf("%ld", &array[c]); | ||||
10 | maximum = array; | ||||
11 | *maximum = *array; | ||||
12 | for (c = 1; c < size; c++) | ||||
13 | { | ||||
14 | if (*(array+c) > *maximum) | ||||
15 | { | ||||
16 | *maximum = *(array+c); | ||||
17 | location = c+1; | ||||
18 | } | ||||
19 | } | ||||
20 | printf("Maximum_element_found_at_location %ld and it's value is %ld.\n", location, *maximum); | ||||
21 | return 0; | ||||
22 | } |
Largest Integer C Programming Code by Using Functions
1 | #include <stdio.h> | |||
2 | int find_maximum(int[], int); | |||
3 | int main() | |||
4 | { | |||
5 | int c, array[100], size, location, maximum; | |||
6 | printf("Input_number of elements_in array\n"); | |||
7 | scanf("%d", &size); | |||
8 | printf("Enter %d integers\n", size); | |||
9 | for (c = 0; c < size; c++) | |||
10 | scanf("%d", &array[c]); | |||
11 | location = find_maximum(array, size); | |||
12 | maximum = array[location]; | |||
13 | printf("Maximum_element_location = %d and value = %d.\n", location + 1, maximum); | |||
14 | return 0; | |||
15 | } | |||
16 | int find_maximum(int a[], int n) | |||
17 | { | |||
18 | int c, max, index; | |||
19 | max = a[0]; | |||
20 | index = 0; | |||
21 | for (c = 1; c < n; c++) | |||
22 | { | |||
23 | if (a[c] > max) | |||
24 | { | |||
25 | index = c; | |||
26 | max = a[c]; | |||
27 | } | |||
28 | } | |||
29 | return index; | |||
30 | } |