The supermarket has different variety of items in different weight. Find maximum weight from these items. Write a program to find maximum weight of an item using dynamic memory allocation.
Runtime Input :
10
2.34
3.43
6.78
2.45
7.64
9.05
5.67
34.95
4.5
3.54
Output :
34.95
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Finding the maximum weight with the Dynamic Memory Allocation
int j,x;
float *coder;
printf("Employing the Dynamic Memory Allocation to find the maximum :\n");
x = 11;
coder=(float*)calloc(x,sizeof(float)); // Memory is allocated for 'n' elements
if(coder==NULL)
{
printf(" No memory allocation.");
exit(0);
}
coder = (float [11]){10,2.34,3.43,6.78,2.45,7.64,9.05,5.67,34.95,4.5,3.54};
printf("\n");
for(j=1;j<x;++j)
{
if(*coder<*(coder+j))
*coder=*(coder+j);
}
printf("The maximum weight is : %.2f \t\t",*coder);
return 0;
}
Comments
Leave a comment