| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 926 人关注过本帖
标题:for语句嵌套问题
取消只看楼主 加入收藏
萧哲君
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2016-10-30
结帖率:87.5%
收藏
已结贴  问题点数:10 回复次数:1 
for语句嵌套问题
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

float tjcs(int);

int main ()
{
    int totalnumbers;
    float percentage;
    int totals;
    int i,j;

    printf("\nPlease enter the totalnumbers:");
    scanf("%f",&totalnumbers);
    printf("\nPlease enter the totals:");
    scanf("%d",&totals);
    for (j=1;j<=totals;j++)
    {
        percentage=tjcs(totalnumbers);
        printf("The percentage of %d is %f",j,percentage);
    }
}
float tjcs(int totalnumbers)
{
    int randvalue;
    int total=0;
    int i;
    float percentage;

    srand(time(NULL));

    for (i=1;i<=totalnumbers;i++)
    {
        randvalue=1+(int)rand() % 100;
        if(randvalue>50)
        total++;
    }
    percentage=total/totalnumbers;
    return(percentage);
}
此程序是本人所编求在有totals种可能,且每种可能性均相同的概率事件中,连续模拟实验totalnumbers次时,每种可能的概率。

但运行时出现问题,求解答是何原因。
搜索更多相关主题的帖子: percentage include 
2016-11-05 15:36
萧哲君
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2016-10-30
收藏
得分:0 
回复 楼主 萧哲君
图片附件: 游客没有浏览图片的权限,请 登录注册

你给出的程序在调试时出现了这些问题,不知道是何原因,求指教,是否是我编译器的问题,我使用的是code::block。



2016-11-07 17:00
快速回复:for语句嵌套问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016487 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved