博文

单精度实数的输出问题!(2007-03-03 15:50:00)

摘要:2007-2-15 20:39:00   http://www.programfan.com/club/showbbs.asp?id=218492 #include "stdio.h"int main(){    float a,b;    char c='a';    int i=97;    a=31.1111;    b=28.333;    printf("%f,%7.4f\n",a+b,a-b);   //a+b输出单精度浮点数不是7位有效数字吗?为什么输出答案是59.444099而不是正确答案59.444100呢?    这里似乎如果存在四舍五入的情况,不用double基本输出的小数都有误差的,除非通过%后的参数限制了输出位数有时才可以得出正确的答案     printf("%c,%d\n",c,c);    printf("%s,%%\n","china");    getchar();}  ......

阅读全文(2801) | 评论:0

scanf的格式别写错了!(2007-03-03 15:44:00)

摘要:2007-2-16 13:12:00    #include"stdio.h"#include"math.h"int main(){    float a,b,c,t,y,x1,x2;    printf("输入a,b,c的值:");    scanf("%f%f%f\n",&a,&b,&c);    y=b*b-4*a*c;    if (y>0)    {        t=sqrt(b*b-4*a*c);        x1=(-b+t)/(2*a);        x2=(-b-t)/(2*a);        printf("x1=%f,x2=%f",x1,x2);    }    if (y<=0)     printf("方程无解");    return(0);} 看出什么问题了吗?当时编译后记得是没结果,原来是scanf("%f%f%f\n",&a,&b,&c);里多了个\n,太大意了!有时也会忘记给定义的变量加上地址&,初学者啊,还是要细心!......

阅读全文(2174) | 评论:1

赋值未定义(2007-03-03 15:31:00)

摘要:2007-2-13 15:56:00 百鸡问题 #include"stdio.h"int main(){    int x,y,z;    x=0;    while (x<=19)    {          y=0;           while (y<=33)          {                z=100-x-y;                if (5*x+3*y+z/3=100)                printf ("%d%d%d\n",x,y,z);                y++;          }          x++;  &......

阅读全文(2015) | 评论:0

记得先定义参数!(2007-03-03 15:28:00)

摘要:2007-2-11 22:14:00 #include "stdio.h"int main(){    int a,b,c;    scanf("%d%d",&a,&b);    c=max(a,b);    printf("max=%d",c);}int max(int x,int y){    int z;    if (x>y) z=x;    else z=y;    return(z);}这段程序为什么会报错大家看出来了吗?那时的我刚刚开始学习,什么形参实参根本就没一点概念,虽然对要先定义再引用还是知道的,不过当时根本就没这想法,正确的应该在int main()前面加上一行int max(int,int)!......

阅读全文(1834) | 评论:0

怎么察看程序运行的结果(2007-03-03 15:25:00)

摘要:2007-2-11 16:39:00    刚刚开始学习的我还不知道怎么中断程序看运行结果,就发了个《问个Dev-C++的使用问题》的帖子!从这天起,知道了后面书上才学到的getchar()获取字符来中断程序观看结果了!......

阅读全文(3046) | 评论:0

新手用的编程工具环境的问题(2007-03-03 15:23:00)

摘要:2007-2-2 22:01:00   发了我在promgramfan的第一个问题贴,从这时开始,我在大家的指导下选择了用Dev-Cpp作为我的编译工具,开始了我的c语言学习之路!......

阅读全文(2075) | 评论:0