CROP DETAILS
Crop Details
A small farmer, Mr.John, use to grow different crops every year in his field. All the crops are being grown using goat manure, farmyard manure, groundnut and neem cake. All the crops are grown organically. He got high yield by using sufficient water and fertilizers at in this year. He will sell his crops in the market.
In the market, he wants to maintain the details of each crop that are purchased by customers.
Details like crop name, the weight of the crop, cost of the crop
Display the details of crops in ascending order of crop names.
Create a structure called crop.
struct crop{
char cropName[30];
float weight;
int cost;
};
Input and Output Format:
Refer sample input and output for formatting specification.
All float values are displayed correctly to 2 decimal places.
All text in bold corresponds to the input and the rest corresponds to output.
Sample Input and Output:
Enter the number of Crops
2
Enter the details of Crop 1
Enter name
potato
Enter Weight
10
Enter Cost
50
Enter the details of Crop 2
Enter name
beans
Enter Weight
12.5
Enter Cost
45
Details of Crops
Crop 1
Name :beans
Weight :12.50
Cost :45
Crop 2
Name :potato
Weight :10.00
Cost :50
#include
#include
#include
struct crop
{
char cropName[30];
float weight;
int cost;
}c[5];
int main()
{
int n,i,j,ct;
float wt;
char temp[30];
printf("Enter the number of Crops\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the details of Crop %d\n",i);
printf("Enter name\n");
scanf("%s",c[i].cropName);
printf("Enter Weight\n");
scanf("%f",&c[i].weight);
printf("Enter Cost\n");
scanf("%d",&c[i].cost);
}
for(i=1;i<=(n-1);i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(c[i].cropName,c[j].cropName)>0)
{
strcpy(temp,c[i].cropName);
strcpy(c[i].cropName,c[j].cropName);
strcpy(c[j].cropName,temp);
wt=c[i].weight;
c[i].weight=c[j].weight;
c[j].weight=wt;
ct=c[i].cost;
c[i].cost=c[j].cost;
c[j].cost=ct;
}
}
}
printf("Details of Crops\n");
for(i=1;i<=n;i++)
{
printf("Crop %d\n",i);
printf("Name:%s\n",c[i].cropName);
printf("Weight:%0.2f\n",c[i].weight);
printf("Cost:%d\n",c[i].cost);
}
return 0;
}
Comments
Post a Comment