整数除法不会得到结果

编程入门 行业动态 更新时间:2024-10-23 08:27:53
本文介绍了整数除法不会得到结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将2的整数相除并获得浮点数的结果,但是看来它不能正常工作.你能看到我在哪里做错了吗? sscanf部分正在工作,问题出在分割部分.

I'm trying to divide 2 integer and get the float results but it does not seem it is working properly. Can you see where am i doing wrong? sscanf part is working, the problem is at the dividing part.

char *latitude = "4055,1792.N"; int val1; int val2; int val3; float result; sscanf ( latitude, "%2d%2d,%4d", &val1, &val2, &val3); printf("\r\nval1 = %d val2 = %d val3 = %d\r\n",val1,val2,val3); result = val1 + (float)val2/(float)60 + (float)val3/(float)600000; printf("\r\nResult = %f\r\n",result); printf("\r\nEnd\r\n");

此代码不会导致此操作.这是输出:

This code does not result this operation. Here is the output:

val1 = 40 val2 = 55 val3 = 1792 Result = End

推荐答案

您正在使用哪个编译器. gcc --version gcc(GCC)4.5.1 20100924(Red Hat 4.5.1-4)

Which compiler you are using . gcc --version gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)

它给出以下结果.

val1 = 40 val2 = 55 val3 = 1792

val1 = 40 val2 = 55 val3 = 1792

结果= 40.919655

Result = 40.919655

更多推荐

整数除法不会得到结果

本文发布于:2023-10-25 13:44:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527120.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:除法   整数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!