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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y;
float *item;
printf(" Enter the number of items to calculate the maximum weight\n");
scanf("%d",&y);
item=(float*)calloc(y,sizeof(float));
if(item==NULL)
{
printf("Memory allocation unsuccessfull.");
exit(0);
}
printf("\n\n");
for(x=0;x<y; x++)
{
printf("Item %d: ",x+1);
scanf("%f",item+x);
}
for(x=1;x<y;x++)
{
if(*item<*(item+x))
*item=*(item+x);
}
printf(" The Maximum item in terms of weight in the supermarket is : %.2f \n\n",*item);
return 0;
}
Comments
Leave a comment