forked from gouravthakur39/beginners-C-program-examples
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLargest.c
More file actions
29 lines (28 loc) · 686 Bytes
/
Largest.c
File metadata and controls
29 lines (28 loc) · 686 Bytes
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
#include<stdio.h>
#include<stdlib.h>
void main()
{
int size, i, max;
int *array;
printf("Enter number of numbers: ");
scanf("%d", &size);
//creating an array of entered size
array = malloc(size * sizeof(int));
printf("Enter %d numbers: \n", size);
//accepting each number and adding them in the array
for(i=0; i<size; i++)
{
scanf("%d", &array[i]);
}
max = array[0];
//traversing the array and comparing each element to integer max
for(i=1; i<size; i++)
{
if(array[i] > max)
{
max = array[i];
}
}
//printing the integer max
printf("The largest number is %d\n", max);
}