Answer to Question #205297 in C for Prasanna

Question #205297

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-10T03:36:16-0400
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i,size;
    float *weights;
	float  maximumWeight;
    scanf("%d",&size);
    weights=(float*)calloc(size,sizeof(float));  
    
    for(i=0;i<size; i++){
       scanf("%f",&weights[i]);
    }
	maximumWeight=weights[0];
	for(i=0;i<size; i++){
		if(maximumWeight<weights[i]){
			maximumWeight=weights[i];
		}
    }


	printf("%.2f\n\n",maximumWeight);
	getchar();
	getchar();
    
    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