Answer to Question #204507 in C for Thanu

Question #204507

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


1
Expert's answer
2021-06-08T07:32:30-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS