| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1908 人关注过本帖
标题:建议计算器源代码里面有几个不理解的问题请指教!
取消只看楼主 加入收藏
弟大勿勃
Rank: 2
等 级:论坛游民
帖 子:186
专家分:59
注 册:2014-4-17
结帖率:81.82%
收藏
已结贴  问题点数:20 回复次数:4 
建议计算器源代码里面有几个不理解的问题请指教!
不理解的地方时下面程序用红色标记的地方。请详细解释一下为什么printf输出的是&string,&Ary_10?难道Ary_10是数组??可以酱紫定义?还是说itoa函数有什么特殊的,能详细说一下吗?




#include <stdio.h>  
#include <math.h>  
#include <stdlib.h>  
//预处理指令  
int main(void)  
{  
        double bNumber, Number, Result;                //给加减乘除定义的变量  
        int No;                //选项的定义变量  
        double a, b, c, x1, x2, Rad;                //给一元一次方程定义的变量  
        int Ary_10;                                        //定义进制的变量  
        char string[32];                //二进制变量定义  
   
        system ("title: www.clang.cc");               
   
        while(1)  
        {  
                //界面  
                printf ("┏ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┓\n");  
                printf ("┇请选择你要计算的方法:                         ┇\n");  
                printf ("┣ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┫\n");  
                printf ("┇  加法请按_1    进制转换_5                    ┇\n");  
                printf ("┇  减法请按_2    求一元二次方程_6              ┇\n");  
                printf ("┇  乘法请按_3                                  ┇\n");  
                printf ("┇  除法请按_4               退出_0             ┇\n");  
                printf ("┗ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┛\n");  
                printf ("Please write down the number:");  
                scanf ("%d",&No);  
   
                if (No == 1)  
                {  
                        //        加法  
                        printf ("        请输入被加数:");  
                        scanf ("%lf",&bNumber);  
                        printf ("        请输入加数:");  
                        scanf ("%lf",&Number);  
                        Result = bNumber + Number;  
                        printf (" 结果是: %lf\n\n",Result);  
                }  
                else if (No == 2)  
                {  
                        //        减法  
                        printf ("        请输入被减数:");  
                        scanf ("%lf",&bNumber);  
                        printf ("        请输入减数:");  
                        scanf ("%lf",&Number);  
                        Result = bNumber - Number;  
                        printf (" 结果是: %lf\n\n",Result);  
                }  
                else if (No == 3)  
                {  
                        //        乘法  
                        printf ("        请输入被乘数:");  
                        scanf ("%lf",&bNumber);  
                        printf ("        请输入乘数:");  
                        scanf ("%lf",&Number);  
                        Result = bNumber * Number;  
                        printf (" 结果是: %lf\n\n",Result);  
                }  
                else if (No == 4)  
                {  
                        //        除法  
                        printf ("        请输入被除数:");  
                        scanf ("%lf",&bNumber);  
                        printf ("        请输入除数:");  
                        scanf ("%lf",&Number);  
                        Result = bNumber / Number;  
                        printf (" 结果是: %lf\n\n",Result);  
                }  
                else if (No == 5)  
                {  
                        //进制转换的代码  
                        printf("请输入需要转换的十进制数:");  
                        scanf("%d", &Ary_10);  
                        itoa (Ary_10, string ,2);  
                        printf("二进制: %s\n", &string);  
                        printf("八进制: %o\n", &Ary_10);  
                        printf("十六进制: %x\n", &Ary_10);  
                }  
                else if (No == 6)  
                {  
                        //求一元二次方程的解的代码  
                        printf("请输入一元一次方程的a,b,c三个数:");  
                        scanf("%lf%lf%lf",&a,&b,&c);  
                        Rad = b*b - 4*a*c;  
                        if (Rad > 0)  
                        {  
                                x1 = -b + sqrt(Rad) / (2*a);  
                                x2 = -b - sqrt(Rad) / (2*a);  
                                printf("有两个解 x1 = %lf, x2 = %lf\n", &x1, &x2);  
                        }  
                        else if (Rad == 0)  
                        {  
                                x1 = -b / (2*a);  
                                printf("只有一个解 x1 = %lf\n", &x1);  
                        }  
                        else  
                        {  
                                printf("无解\n");  
                        }  
                }  
                else if (No == 0)  
                {  
                        //        退出程序  
                        break;  
                }  
                else  
                {  
                        //        输入的选项不对  
                        printf("  请输入正确的数字。\n\n");  
                }  
                system ("pause");        //按任意键继续  
                system ("cls");                //清屏  
        }  
        return 0;  
        getchar();  
}  
搜索更多相关主题的帖子: 计算器 include 源代码 double 
2016-07-22 16:16
弟大勿勃
Rank: 2
等 级:论坛游民
帖 子:186
专家分:59
注 册:2014-4-17
收藏
得分:0 
在线等哦,谢谢回帖的好人。
2016-07-22 16:17
弟大勿勃
Rank: 2
等 级:论坛游民
帖 子:186
专家分:59
注 册:2014-4-17
收藏
得分:0 
别沉啊,下班的师傅们看一眼吗
2016-07-22 16:28
弟大勿勃
Rank: 2
等 级:论坛游民
帖 子:186
专家分:59
注 册:2014-4-17
收藏
得分:0 
回复 4楼 吹水佬
那为什么要加个‘&’,这个是输出数组时才加的啊?Ary_10定义时不是数组吧?
2016-07-22 16:34
弟大勿勃
Rank: 2
等 级:论坛游民
帖 子:186
专家分:59
注 册:2014-4-17
收藏
得分:0 
回复 5楼 弟大勿勃
可是我编译程序时都正确呢...
2016-07-25 09:18
快速回复:建议计算器源代码里面有几个不理解的问题请指教!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040715 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved