Answer to Question #203031 in C for Nanba

Question #203031

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


1
Expert's answer
2021-06-04T06:07:58-0400
#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;
}

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