C语言编程练习(二)
1、在屏幕上输出如下图形 键盘输入n,比如输入3如下
*
* *
* * *
void printStar()
{
printf("Please input the line of star:");
int n = 0;
scanf("%d", &n);
int index = 0;
int numofStar = 0;
int numofNull = 0;
for(index=1; index<=n; index++)
{
for(numofNull=0; numofNull<n-index; numofNull++)
{
printf(" ");
}
for(numofStar=0; numofStar<index; numofStar++)
{
printf("* ");
}
printf("\n");
}
}
2、一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
void countMeter()
{
double initHigh = 100;
int num = 10;
int index = 0;
double sumMeter = 0;
for(index=0; index<num; index++)
{
sumMeter += initHigh + initHigh/2.0;
initHigh = initHigh/2.0;
}
printf("Sum of distances are:%lf\n", sumMeter-initHigh);
printf("The tenth return %lf meters.\n"