大学大一c语言程序设计实验室上机题全部代码答案实验报告.doc
文本预览下载声明
C语言实验?报告
实验1-1:
hello? world?程序:
源代码:
#inclu?destdio?.h
main()
{
print?f(hello? world?!\n);
syste?m(pause?);
}
实验1-2:
完成3个数?据的输入、求和并输出?计算结果的?程序:
源代码:
#inclu?destdio?.h
main()
{
int i,j,k,sum;
scanf?(%d%d%d,i,j,k);
sum=i+j+k;
print?f(sum=%d,sum);
syste?m(pause?);
实验1-3:
在屏幕上输?出如下图形?:
A
BBB
CCCCC?
源代码:
#inclu?destdio?.h
main()
{
print?f( A\n);
print?f( BBB\n);
print?f( CCCCC?\n);
syste?m(pause?);
}
实验2-1:
计算由键盘?输入的任何?两个双精度?数据的平均?值
源代码:
#inclu?destdio?.h
main()
{
doubl?e a,b;
scanf?(%lf%lf,a,b);
print?f(%.1lf\n,(a+b)/2);
syste?m(pause?);
}
实验2-2:
写一个输入?7个数据的?程序,把输入的数?据代入a + b * (c – d ) / e * f – g 表达式进行?运算
源代码:
#inclu?destdio?.h
main()
{
float? a,b,c,d,e,f,g,x;
scanf?(%f%f%f%f%f%f%f,a,b,c,d,e,f,g);
x=a + b * (c - d ) / e * f - g;
print?f(x=%f,x);
syste?m(pause?);
}
实验2-3:
编写一个C?语言程序,测试下列各?表达式:
i, j
i + 1 , j + 1
i++ , j++
++i , ++j
i+++++j
源代码:
#inclu?destdio?.h
main()
{
int i=1,j=1;
print?f(%d %d\n,i+1,j+1);
print?f(%d %d\n,i++,j++);
print?f(%d %d\n,++i,++j);
print?f(%d\n,(i++)+(++j));
syste?m(pause?);
}
实验2-4:
输入存款金?额mone?y,存期yea?r和年利率?rate,根据下列公?式计算存款?到期时的利?息inte?rest(税前),输出时保留?2位小数。
inter?est = money?(1+rate)year - money?
源代码:
#inclu?destdio?.h
#inclu?demath.h
main()
{
int year=2;
float? rate=0.1,money?=1000;
float? futur?eMone?y;
futur?eMone?y=money?*pow((1+rate),year);
print?f(%10.2f,futur?eMone?y);
syste?m(pause?);
}
实验2-5:
输入华氏温?度,输出对应的?摄氏温度。计算公式如?下:
c = 5 * ( f - 32) / 9
其中,c表示摄氏?温度,f表示华氏?温度
源代码:
#inclu?destdio?.h
main()
{
int c,f;
scanf?(%d,f);
c = 5 * ( f - 32) / 9;
print?f(%d,c);
syste?m(pause?);
}
实验3-1:
编写一个程?序完成输入?一个整数,输出它的符?号
源代码:
#inclu?destdio?.h
main()
{
int i;
scanf?(%d,i);
if(i0)
print?f(+);
els
显示全部