第一次任务

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

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;
}
      

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

第一次就写到这了。大家看到了就共勉吧! 加油!~!


     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值