《C语言及程序设计》实践项目——数据的输出

来源:互联网 发布:js radio disabled 编辑:程序博客网 时间:2024/06/05 20:08

返回:贺老师课程教学链接  C语言及程序设计初步  


【阅读程序题】

1、写出以下程序的输出结果,再在计算机上运行程序。对比两结果是否相同,以此检查自己的学习效果。
2、遇到在视频中未讲的格式控制符,上网搜索发现其用途。
(1)

#include <stdio.h>int main(){    int a=12345;    float b=-198.345, c=6.5;    printf("a=%4d,b=%-10.2e,c=%6.2f\n",a,b,c);    return 0;}


(2)
#include <stdio.h>int main(){    int x=-2345;    float y=-12.3;    printf("%6d, %6.2f",x,y);    return 0;}


(3)
#include <stdio.h>int main(){    int a=252;    printf("a=%o a=%#o\n",a,a);    printf("a=%x a=%#x\n",a,a);    return 0;}


(4)
#include <stdio.h>int main(){    int x=12;    double a=3.1415926;    printf("%6d, %-6d, %6d\n",x,x,x);    printf("%14.10lf\n",a);    return 0;}


参考结果:

(1)

a=12345,b=-1.98e+002,c=  6.50


(2)

 -2345, -12.30


(3)

a=374 a=0374
a=fc a=0xfc


(4)

    12, 12    ,     12
  3.1415926000



0 0
原创粉丝点击