| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 461 人关注过本帖
标题:VC 哪位高手帮我看看呀~~谢谢~~
只看楼主 加入收藏
pemi2010
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-2-20
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
VC 哪位高手帮我看看呀~~谢谢~~
#include <stdio.h>
#include <stdlib.h>

void main()
{
    int r;  /*the approximate length of probable crime scope */
    int x1; /*the number of commited crime spots*/
    float c,d,e,f;/*probability of the spot weighed by distance*/
    int i,j,k;/*loop control variable*/

    printf("Please input the approximate length(integer) of probable crime scope:\n");
    int ret;
    ret=scanf("%d",&r);
    if (ret==0)
    {
        printf("Input r data type error!\n");
        fflush(stdin);
    }
    else if(ret==EOF)
    {
        printf("Input r failure occures!\n");
    }
    else
    {
        printf("Please input the number of commited crime spots:(<100)");
        int ret2;
        ret2=scanf("%d",&x1);
        if (ret2==0)
        {
            printf("Input x1 data type error!\n");
            fflush(stdin);
        }
        else if(ret2==EOF)
        {
            printf("Input x1 failure occures!\n");
        }
        else if(x1>=100)
        {
            printf("too large!!!x1 can't be larger than 100!");
        }

        else
        {
            int a[100];
            int b[100];

            printf("Please input the modified abscissa in order:\n");
            for(i=0;i<x1;i++)
            {
                scanf("%d",&a[i]);
            }

            printf("Please input the modified ordinates in order:\n");
            for(j=0;j<x1;j++)
            {
                scanf("%d",&b[j]);
            }


            float matrix[100][100];/*store the probabilities of each spot*/
            for(i=0;i<r;i++)
            {
                for(j=0;j<r;j++)
                {
                    for(k=0;k<x1;k++)
                    {
                        if((i==a[k])&&(j==b[k]))
                        {
                            matrix[i][j]=1;
                        }
                        else
                        {
                            matrix[i][j]=0;
                        }
                    }
                }
            }

            printf("Enter the probabilities of the spots in order:cdef\n");
            scanf("%f",&c);
            scanf("%f",&d);
            scanf("%f",&e);
            scanf("%f",&f);

            for(i=0;i<x1;i++)
            {
                for(j=0;j<r;j++)
                {
                    for(k=0;k<r;k++)
                    {
                        if((a[i]-j<=3)&&(a[i]-j>=-3)&&(b[i]-k<=3)&&(b[i]-k>=-3))
                        {
                            matrix[j][k]+=c;
                        }
                        else if((a[i]-j<=6)&&(a[i]-j>=-6)&&(b[i]-k<=6)&&(b[i]-k>=-6))
                        {
                            matrix[j][k]+=d;
                        }
                        else if((a[i]-j<=9)&&(a[i]-j>=-9)&&(b[i]-k<=9)&&(b[i]-k>=-9))
                        {
                            matrix[j][k]+=e;
                        }
                        else if((a[i]-j<=12)&&(a[i]-j>=-12)&&(b[i]-k<=12)&&(b[i]-k>=-12))
                        {
                            matrix[j][k]+=f;
                        }
                    }
                }
            }


            float max=matrix[0][0];
            int row=0;
            int column=0;
            for(i=0;i<r;i++)
            {
                for(j=0;j<r;j++)
                {
                    if(max<matrix[i][j])
                    {
                        max=matrix[i][j];
                        row=i;
                        column=j;
                    }
                }
            }
            printf("max=%f,row=%d,column=%d\n",max,row+1,column+1);


            printf("all probabilities within the crime scope is like this:\n");
            for(i=0;i<r;i++)
            {
                for(j=0;j<r;j++)
                {
                    printf("%5.4f ",matrix[i][j]);
                }
                printf("\n");
            }
        }
        
    }

}   
最后最大值那一块貌似没执行的说,还有您帮忙看看最后出那样的结果是对的么?
搜索更多相关主题的帖子: distance probable control include number 
2010-02-20 18:46
pemi2010
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-2-20
收藏
得分:0 
坐等回复
2010-02-20 19:00
dydsdyds
Rank: 6Rank: 6
来 自:Java
等 级:侠之大者
帖 子:217
专家分:457
注 册:2010-2-14
收藏
得分:10 
加点注释,我洋文学的不好

c语言刚开一学期,就换开VB...
2010-02-21 19:43
幸运之星
Rank: 4
来 自:吉林
等 级:业余侠客
帖 子:275
专家分:239
注 册:2009-6-5
收藏
得分:10 
你的程序错误真是太多了啊 这个是我帮你修改的代码
程序代码:
#include <stdio.h>
#include <stdlib.h>

void main()
{
    int r;  
    int x1;
    float c,d,e,f;
    int a[100];
    int b[100];
    int ret=0;
    int ret2;
    int row=0;
    int column=0;
    int i,j,k;
    float matrix[100][100];
    float max=0;
    printf("Please input the approximate length(integer) of probable crime scope:\n");
    ret=scanf("%d",&r);
    if (ret==0)
    {
        printf("Input r data type error!\n");
        fflush(stdin);
    }
    else if(ret==EOF)
    {
        printf("Input r failure occures!\n");
    }
    else
    {
        printf("Please input the number of commited crime spots:(<100)");
        ret2=scanf("%d",&x1);
        if (ret2==0)
        {
            printf("Input x1 data type error!\n");
            fflush(stdin);
        }
        else if(ret2==EOF)
        {
            printf("Input x1 failure occures!\n");
        }
        else if(x1>=100)
        {
            printf("too large!!!x1 can't be larger than 100!");
        }

        else
        {


            printf("Please input the modified abscissa in order:\n");
            for(i=0;i<x1;i++)
            {
                scanf("%d",&a[i]);
            }

            printf("Please input the modified ordinates in order:\n");
            for(j=0;j<x1;j++)
            {
                scanf("%d",&b[j]);
            }


            for(i=0;i<r;i++)
            {
                for(j=0;j<r;j++)
                {
                    for(k=0;k<x1;k++)
                    {
                        if((i==a[k])&&(j==b[k]))
                        {
                            matrix[i][j]=1;
                        }
                        else
                        {
                            matrix[i][j]=0;
                        }
                    }
                }
            }

            printf("Enter the probabilities of the spots in order:cdef\n");
            scanf("%f",&c);
            scanf("%f",&d);
            scanf("%f",&e);
            scanf("%f",&f);

            for(i=0;i<x1;i++)
            {
                for(j=0;j<r;j++)
                {
                    for(k=0;k<r;k++)
                    {
                        if((a[i]-j<=3)&&(a[i]-j>=-3)&&(b[i]-k<=3)&&(b[i]-k>=-3))
                        {
                            matrix[j][k]+=c;
                        }
                        else if((a[i]-j<=6)&&(a[i]-j>=-6)&&(b[i]-k<=6)&&(b[i]-k>=-6))
                        {
                            matrix[j][k]+=d;
                        }
                        else if((a[i]-j<=9)&&(a[i]-j>=-9)&&(b[i]-k<=9)&&(b[i]-k>=-9))
                        {
                            matrix[j][k]+=e;
                        }
                        else if((a[i]-j<=12)&&(a[i]-j>=-12)&&(b[i]-k<=12)&&(b[i]-k>=-12))
                        {
                            matrix[j][k]+=f;
                        }
                    }
                }
            }

            max=matrix[0][0];
            for(i=0;i<r;i++)
            {
                for(j=0;j<r;j++)
                {
                    if(max<matrix[i][j])
                    {
                        max=matrix[i][j];
                        row=i;
                        column=j;
                    }
                }
            }
            printf("max=%f,row=%d,column=%d\n",max,row+1,column+1);


            printf("all probabilities within the crime scope is like this:\n");
            for(i=0;i<r;i++)
            {
                for(j=0;j<r;j++)
                {
                    printf("%5.4f ",matrix[i][j]);
                }
                printf("\n");
            }
        }
        
    }

} 


这个可以吧 呵呵
2010-02-24 23:35
快速回复:VC 哪位高手帮我看看呀~~谢谢~~
数据加载中...
 
   



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

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