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()
{
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;
}
Comments
Leave a comment