C语言 实验三C语 实验三
1221410042 张锦华
18.3 最简单的C程序设计
-----实验报告
(1)①源程序
#include
void main()
{int a,b;
float d,e;
char c1,c2;
double f,g;
long m,n;
unsigned int p,q;
a=61;b=62;
c1='a';c2='b';
d=3.56;e=-6.87;
f=3157.890121;g=0.123456789;
m=50000;n=-60000;
p=32768;q=40000;
printf("a=%d,b=%d\nc1=%c,c2=%c\nd=%6.2f,e=%6.2f\n",a,b,c1,c2,d,e);
printf("f=%15.6f,g=%15.12f\nm=%ld,n=%ld\np=%u,q=%u\n",f,g,m,n,p,q);
}
编译结果:
--------------------Configuration: 18.31 - Win32 Debug--------------------
Compiling...
18.31.c
C:\Documents and Settings\Administrator\物理学院张锦华C语言\18.31.c(11) : warning C4305: '=' : truncation from 'const double ' to 'float '
C:\Documents and Settings\Administrator\物理学院张锦华C语言\18.31.c(11) : warning C4305: '=' : truncation from 'const double ' to 'float '
18.31.obj - 0 error(s), 0 warning(s)
②运行结果:
③修改后源程序
#include
void main()
{int a,b;
float d,e;
char c1,c2;
double f,g;
long m,n;
unsigned int p,q;
a=61;b=62;
c1=a;c2=b;
d=3.56;e=-6.87;
f=3157.890121;g=0.123456789;
d=f;e=g;
p=a=m=50000;q=b=n=-60000;
printf("a=%d,b=%d\nc1=%c,c2=%c\nd=%6.2f,e=%6.2f\n",a,b,c1,c2,d,e);
printf("f=%15.6f,g=%15.12f\nm=%ld,n=%ld\np=%u,q=%u\n",f,g,m,n,p,q);
}
编译结果:
--------------------Configuration: 18.31 - Win32 Debug--------------------
Compiling...
18.31.c
C:\Documents and Settings\Administrator\物理学院张锦华C语言\18.31.c(11) : warning C4305: '=' : truncation from 'const double ' to 'float '
C:\Documents and Settings\Administrator\物理学院张锦华C语言\18.31.c(11) : warning C4305: '=' : truncation from 'const double ' to 'float '
C:\Documents and Settings\Administrator\物理学院张锦华C语言\18.31.c(13) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
C:\Documents and Settings\Administrator\物理学院张锦华C语言\18.31.c(13) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
18.31.obj - 0 error(s), 0 warning(s)
修改后运行结果:
④修改后源程序
#include
void main()
{int a,b;
float d,e;
char c1,c2;
double f,g;
long m,n;
unsigned int p,q;
scanf("%d