您的位置:首页 > 其它

第一次任务

2010-11-18 23:50 183 查看
拖了好久的行动终于开始了,很愧疚。希望这次是个好的开头,能每个星期坚持下去!也希望大家能一起努力!相信我们小组每个人都会坚持走一下,最终达到自己的目的,得到自己想要的,也让咱董家娃同志高兴一下!

1-1.
一个球从100m高度落下,每次落地后反跳回原高度的一半,再落下,再反弹。求它才第10次落地时,共经过多少米?第10次反弹多高?



#include "stdio.h"
int main()
{
int i;
float h=100.0,s=0.0,lh;
for (i=1;i<=10;i++)
{
s=s+2*h;
h=h/2;
}
s=s-100;
lh=h;
printf("the path length is %f and the last height is %f",s,lh);
getchar();
}


1-2.
给一个不多于5位的正整数,要求:
1)求出它是几位数;
2)分别输出每一位数字;
3)按逆序输出每一位数字,例如原数字是123,应输出321.


#include "stdio.h"
int main()
{
int a,b,c,d,e,x,h=0,i;
int q[5];
printf("Please input the count./n");
scanf("%d",&x);
a=q[0]=x/10000;
b=q[1]=(x-a*10000)/1000;
c=q[2]=(x-a*10000-b*1000)/100;
d=q[3]=(x-a*10000-b*1000-c*100)/10;
e=q[4]=x%10;
for (i=0;1<=4;i++)
{
if (q[i]==0)
continue;
h=4-i+1;
break;
}
printf("It's digits is %d./n",h);
switch(h)
{
case 5 : printf("%d/n%d/n%d/n%d/n%d/n",a,b,c,d,e);break;
case 4 : printf("%d/n%d/n%d/n%d/n",b,c,d,e);break;
case 3 : printf("%d/n%d/n%d/n",c,d,e);break;
case 2 : printf("%d/n%d/n",d,e);break;
case 1 : printf("%d/n",e);
}
for (i=4;i>=4-h+1;i--)
printf("%d",q[i]);
getch();
return 0;
}




感觉这个程序写的好傻x,自己都看的别扭,那么长的题目,咋就写了这么长的程序。尤其那个 switch 用的。。 可是也就想到这么多了。唉。

1-3.
编一个函数,由实参传来一个字符串,统计此字符串中的字母、数字、空格、其他字符的个数,在主函数中输入字符串以及输出上述结果。


#include "stdio.h"
int ch=0,digit=0,space=0,other=0;
void count(char str[])
{
int i;
for (i=0;str[i]!='/0';i++)
{
if ((str[i]>='a')&&(str[i]<='z')||(str[i]>='A')&&(str[i]<='Z'))
ch++;
else if ((str[i]>='0')&&(str[i]<='9'))
digit++;
else if (str[i]==' ')
space++;
else other++;
}
}
int main()
{
char a[80];
printf("Please input the chars./n");
gets(a);
puts(a);
count(a);
printf("%d,%d,%d,%d",ch,digit,space,other);
getch();
return 0;
}


这个用全局变量就省了实参和形参之间转换的麻烦了,不然还得用指针~~

第一次就写到这了。大家看到了就共勉吧! 加油!~!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: