程序设计与实践(C)课程实验报告
课程名称:程序设计与实践(C)
专业:
班级:
学号:
姓名:
任课教师:
2017 年月日
1市尺=33.3333333厘米(cm)
#include "string.h"
void kp1_1()
{
double si_k;
int si_k1;
char si_xh[3];
printf("输入长裤的腰围(单位是市尺)");
scanf(" ①",&si_k);
si_k1= ②;
if(③) strcpy(si_xh,"ER");
else if(④) strcpy(si_xh,"XL");
else if( ⑤) strcpy(si_xh,"L");
else if( ⑥strcpy(si_xh,"M");
⑦strcpy(si_xh,"S");
printf("长裤的腰围为:%.1lf尺,%d厘米型号:%s",si_k,si_k1,si_xh);
system("pause");
}
运行结果样例
3-2 程序功能:有一批长裤需要贴型号标签,长裤的腰围通过随机数产生,随机数范围74至86,输出该长裤的型号,XL 腰围86-84 , L 腰围83-82, M 腰围81-77 , S 腰围76-74。
这批裤子的数量用户自行输入。
并统计各型号的长裤数量。
#include "string.h"
#include "time.h"
void kp1_2()
{
int si_k1,m,i,a[4]={0};
char si_xh[3];
srand((unsigned)time(NULL));
printf("输入长裤的数量");
scanf("%d",&m);
for(i=1;i<= ①;i++)
{
si_k1= ②;
if(③) {strcpy(si_xh,"XL");(④;}
else if(⑤) {strcpy(si_xh,"L");a[1]++;}
else if( ⑥) {strcpy(si_xh,"M");a[2]++;}
else {strcpy(si_xh,"S");a[3]++;}
printf("长裤的腰围为:%d厘米型号:%s\n",si_k1,si_xh);}
printf("\n\nXL 型号:%d条\tL 型号:%d条\tM 型号:%d条\tS 型号:%d条\n", ⑦);
system("pause");
}
运行结果样例
3-3程序功能:从30岁开始每年投入12000元购买基金定投,请设计一个函数能够根据所输入的年平均收益率和年平均通货膨胀率,计算从30岁到60岁退休时的收益总额。
#include <math.h>
int years = 30;
double oneyear(int year,double earning,double inflation)
{
double temp1,temp2,result;
temp1=1+earning-inflation;
temp2=①;
result = 12000*(1-temp2)/(1-temp1)+12000;
return ②;
}
void kp1_3()
{
int i;
float earning,inflation;
double total;
i = ③;
total = 0;
printf("\nPlease input the avarege yield: ");
scanf("%f",&earning);
printf("\nPlease input the annual inflation rate: ");
scanf("%f",&inflation);
for(;i>0; (④)
total += oneyear(i,(double) earning,(double) inflation);
printf("the total of earning and principal: %f\n",(⑤);
system("pause");
}
运行结果样例
4、编写程序题
4-1程序功能:输入3个任意整数,按由小到大的顺序输出排序后的结果(屏幕显示,同时存入数据文件bdata.txt中。
)(屏幕显示即可,暂时不需要存入数据文件中)
样例数据
输入:12 56 7
输出:原输入数据为:12,56,7 排序后为:7,12,56
提示:文件创建代码段
FILE *fp=NULL;//定义文件指针。