shunfurh
编程介的小学生
采纳率92.7%
2018-12-06 12:45

求解一个概率方面的问题,用C语言来写:

已采纳

Problem Description
Mickey is interested in probability recently. One day , he played a game which is about probability with mini.First mickey gives a letter and a word to mini.Then mini calculate the probability that the letter appears in the word.For example,give you the letter "a" and the word "apple". the probability of this case is 0.20000.

Input
The input contains several test cases. Each test case consists of a letter and a word.The length of the word is no longer than 200.

Output
For each test case, print the probability rounded to five digits after the decimal point.

Sample Input
a apple
c Candy
a banana

Sample Output
0.20000
0.20000
0.50000

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2年前
  • qq_42650817 摸爬滚打一路向前 3年前

    #include
    #include
    void main()
    { char str[5] = "apple";//将所需测试的字符串数组放进字符数组里
    char a='a';//目标字符
    int num=0, i=0;
    //循环检测整个字符数组
    for(i=0;i<5;i++)
    {
    if(str[i]==a)
    num++;
    }
    printf("%f",num/5.000);//注意不能用num/5 至于为什么我想你可以在书本教基础数据类型里有说到
    }
    这些都是简单的知识如果你要学习c的话遇到问题先看回顾一下课本

    点赞 评论 复制链接分享