资源描述
实 验 报 告
《高级语言程序设计》
2009~2010学年第 二 学期
学院(部)
管理学院
指导教师
李跃文
学 号
姓 名
成 绩
高级语言程序设计综合实验一
一.实验目的:
通过本实验更深入的了解高级语言循环结构的程序设计
二.实验内容:
使用循环结构输出九九乘法表。要求实现屏幕分别输出为以下四种形式:
三.操作步骤:
(1)#include <stdio.h> (2)#include <stdio.h>
void main() void main()
{ {
int i,j; int i,j;
for(i=1;i<10;i++) for(i=1;i<10;i++)
{ {
for(j=1;j<=i;j++) for(j=1;j<=10-i;j++)printf(" ");
printf("%2d*%2d=%2d",i,j,i*j); for(j=1;j<=i;j++) printf("%2d*%2d=%2d",i,j,i*j);
printf("\n"); printf("\n");
} }
} }
(3)#include <stdio.h> (4)#include<stdio.h>
void main() void main()
{ {
int i,j; int i,j;
for(i=9;i>=1;i--) for(i=9;i>=1;i--)
{ {
for(j=1;j<=i;j++) for(j=1;j<10-i;j++) printf(" ");
printf("%2d*%2d=%2d",i,j,i*j); for(j=1;j<=i;j++) printf("%2d*%2d=%2d",i,j,i*j);
printf("\n"); printf("\n");
} }
} }
四.实验收获和建议:
高级语言程序设计综合实验二
一.实验目的:
通过本实验更深入的了解高级语言函数的使用合算法设计
二.实验内容:
张先生决定从30岁开始每年投入12000元购买基金定投,请设计一个函数能够根据张先生输入的年平均收益率和年平均通货膨胀率,计算张先生到60岁退休时的收益总额。
三.操作步骤:
#include <stdio.h>
#include <math.h>
int years = 30;
double oneyear(int year,double earning,double inflation)
{
double temp1,temp2,result;
temp1 = 1 + earning – inflation;
temp2 = pow(temp1,(double) year);
result = 12000*(1-temp2)/(1-temp1)+12000;
return result;
}
int main(int argc, char *argv[])
{
int i;
float earning,inflation;
double total;
i = years;
total = 0;
printf(“\nPlease input the avarege yield: ”);
scanf(“%f”,&earning);
printf(“\nPlease input the annual inflation rate: ”);
scanf(“%f”,&inflation);
for(;i>0;i--)
total += oneyear(i,(double) earning,(double) inflation);
printf(“the total of earning and principal: %f\n”,total);
return 0;
}
四.实验收获和建议:
高级语言程序设计综合实验三
一.实验目的:
通过本实验更深入的了解函数和数组的应用
二.实验内容:
请为小学生设计一个考试程序,能够连续出10道加法题目,每次一题,如果答案正确,进入下一道题目,否则要重复回答该题,但是每一题最多有三次回答机会,题目回答完毕后计算学生的得分并判断等级(Excellent, Good, Normal, Passed, No Passed)。
三.操作步骤:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main()
{
int score=0,num,a1,a2,answer,chance;
srand(time(NULL));
for(num=0;num<10;num++)
{
a1=rand()%100+1;
a2=rand()%100+1;
chance=2;
for(;;)
{
printf("%d+%d=",a1,a2);
scanf("%d",&answer);
if(answer==a1+a2) {score+=10; break;}
else if(chance>0) {printf("Wrong!You have %d time(s) to try\n",chance);chance--;}
else {printf("You lose 10 points\n");break;}
}
}
printf("You get %d points,",score);
if(score<60) printf("No Passed\n");
else if(score<70) printf("Passed\n");
else if(score<80) printf("Normal\n");
else if(score<90) printf("Good\n");
else printf("Excellent\n");
}
四.实验收获和建议:
展开阅读全文