第一次任务
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;
}
这个用全局变量就省了实参和形参之间转换的麻烦了,不然还得用指针~~
第一次就写到这了。大家看到了就共勉吧! 加油!~!
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;
}
这个用全局变量就省了实参和形参之间转换的麻烦了,不然还得用指针~~
第一次就写到这了。大家看到了就共勉吧! 加油!~!
相关文章推荐
- 第一次完成工作任务 ^_^
- 第一次上机任务
- HTML/CSS第一次作业(小薇学院任务)
- 任务08——第一次半月学习总结
- 第一次任务
- 第一次实验任务
- 第一次任务小计(一)
- 接受第一次任务
- 八周第一次课 2017.12.4 linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、target介绍
- 第一次接到的任务
- 翻译团队第一次翻译任务[2006.1.18公告]
- 程序设置了多个定时任务,AlarmManager每次都执行第一次出发的那个
- 翻译团队第一次翻译任务[2006.1.18公告]
- 第一次任务完成情况
- 第一次任务为存储过程
- 完成第一次工作的第一个任务
- 第一次带项目遇到的复杂问题如何解决?学会任务分解,勇敢迈出第一步!
- 第一次冲刺任务
- 第一次上机任务之《华氏温度与摄氏温度的对照表之一》