Source Code
// 43. Program to find largest number using dynamic memory allocation
// Arpan Das - CST 2nd Year (VOCLET)
#include <stdio.h>
#include <malloc.h>
void main () {
int n, i, max, *ar;
//clrscr();
printf("\t\t..:: find largest number using dynamic memory allocation ::..\n\n");
printf("Please enter the number of numbers to be entered: ");
scanf("%d", &n);
ar = (int *) malloc(n * sizeof(int));
for (i=0; i<n; i++) {
printf("\nEnter element no %d: ", i+1);
scanf("%d", &ar[i]);
}
max = ar[0];
for (i=0; i<n; i++)
if (max < ar[i]) max = ar[i];
printf("\nThe largest number is %d", max);
//getch();
}
Output
..:: find largest number using dynamic memory allocation ::..
Please enter the number of numbers to be entered: 5
Enter element no 1: 12
Enter element no 2: 45
Enter element no 3: 3
Enter element no 4: 65
Enter element no 5: 7
The largest number is 65