C Online Compiler
Example: C Program to Find Largest Number Using Dynamic Memory Allocation
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find Largest Number Using Dynamic Memory Allocation #include <stdio.h> #include <stdlib.h> // It's the main function of the program int main() { int count; double *data_container; // Step-1 Take input from the user printf("Enter the element counts: "); scanf("%d", &count); // Step-2 Allocate the memory to Nth elements data_container = (double *)calloc(count, sizeof(double)); if (data_container == NULL) { printf("Memory allocation failed!"); exit(0); } // Step-3 Take input of Nth elements by the user and store into 'data_container' for (int i = 0; i < count; i++) { printf("INPUT-[%d]: ", i + 1); scanf("%lf", data_container + i); } // Step-4 Find the largest number from 'data_container' for (int i = 0; i < count; i++) { if (*data_container < *(data_container + i)) { *data_container = *(data_container + i); } } // Step-5 Print the largest number output of the program printf("Largest Number: %.2lf\n", *data_container); // Step-6 Release 'data_container' from Allocated Memory free(data_container); return 0; }
10 4 8 10 25 90 34 67 20 5 80
Output
Clear
ADVERTISEMENTS