在结构的变量中找到最小值和最大值(C程序) [英] Find minimum and maximum value in a variable of a struct (C program)

查看:95
本文介绍了在结构的变量中找到最小值和最大值(C程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储销售数据的结构。我想创建一个函数来查找stsales结构中浮点变量(final_price)的最大值和最小值。



我的结构:



I have a struct to store sales data. And i want to make a function to find the max and min value of a float variable (final_price) that is inside stsales struct.

My struct:

typedef struct{
int idcustomersale;
char serialnumberproductsale[10]
float final_price;
}stsales;


int main()
{

   stsales sales[1000];
   int countsales=0;

}

//Code of function find_min_max...........





任何帮助!!!!



Any help!!!!

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!



这并不难 - 你需要做的就是设置一个最大值和最小值,然后循环通过数组中的每个值检查每个值。如果找到小于最小值,请将其设置为1。同样为最大值。在循环之后,你有最大值和最小值

提示:如果你考虑它,你可以将最大值和最小值的初始值设置为相同的值,但它不会是相同的每次执行程序....
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

This isn't difficult - all you need to do is set up a max and min value, then loop though each of the values in your array checking each against both. If you find a smaller-than-minimum value, set it to the one one. Similarly for the maximum. After the loop, you have the max and min values
Hint: You can set the initial value of both maximum and minimum to the same value if you think about it, but it won't be the same for each time you execute your program....


这篇关于在结构的变量中找到最小值和最大值(C程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆