如何删除这些错误并计算运行时间 [英] How can I remove those errors and calculate runtime

查看:77
本文介绍了如何删除这些错误并计算运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
        #include <time.h>

        int MaxSubsequenceSum( int,int);
        int  main (void){

            clock_t start, end;
            double run_time;
            int rtime1=((int)run_time);
            double rtime2=(run_time-rtime1)*1000;


              start = clock();
            MaxSubsequenceSum( int A[],int N);

              end = clock();

              run_time=(end-start)/((double)CLOCKS_PER_SEC);
              printf("The runtime of code is %d seconds and %f milliseconds/n",rtime1,rtime2);
            return 0;
        }

        int MaxSubsequenceSum(int A[],int N)
         {

            int ThisSum,MaxSum,i,j;
                MaxSum=0;
                for(i=0;i<N;i++)
                {
                    ThisSum = 0;
                    for(j=i;j<N;j++)
                    {
                        ThisSum +=A[j];
                        if(ThisSum>MaxSum)
                            MaxSum=ThisSum;
                    }
                    }

                    return MaxSum;

         }



所以上面提到的代码和错误是:

。:几个函数的参数MaxsubsequenceSum (在通话中)

。冲突类型MaxsubsequenceSum(在功能的定义中)



我尝试过:



i尝试在主函数之前更改变量类型,数组大小,声明但没有任何效果。


SO the above mentioned is the code and errors are :
.too few arguments to function MaxsubsequenceSum(in calling)
.conflicting types of MaxsubsequenceSum(in defination of function)

What I have tried:

i tried to change variables types ,array size ,declaration before main function but nothing worked.

推荐答案

Quote:

.conflicting MaxsubsequenceSum的类型(在函数的定义中)

.conflicting types of MaxsubsequenceSum(in defination of function)



问题在于原型,第一个参数是 int


problem is in prototype, first parameter is an int

int MaxSubsequenceSum( int,int);



并且在函数中是一个数组的整数


and in function is an array of ints

int MaxSubsequenceSum(int A[],int N)



您需要选择你想要什么,并使两者匹配。


You need to chose what you want and make both match.


这是旧式C函数声明(也称为原型):

This is an old style C function declaration (also called prototype):
int MaxSubsequenceSum( int,int);

它用于允许在实现之前调用该函数。因此,它也称为前向声明



这是函数定义(实现):

It is used to allow calling that function before the implementation. Therefore, it also called forward declaration.

This is the function definition (the implementation):

int MaxSubsequenceSum(int A[],int N)
{
    /* ... */
}



您的第一个错误是那些不相同。因此,您应该将声明更改为:


Your first error is that those are not identical. So you should change the declaration to:

int MaxSubsequenceSum( int[],int);

或更好地:

or better to:

int MaxSubsequenceSum(int A[],int N);





现在用法(调用函数) )。您正在使用



Now to the usage (calling the function). You are using

MaxSubsequenceSum( int A[],int N);

这又是一个声明但不是函数调用。你必须使用这样的参数必须是现有变量:

which is again a declaration but not a function call. You have to use something like this where the parameters must be existing variables:

int A[] = { 1, 2, 3 };
int N = 3; /* or N = sizeof(A) / sizeof(A[0]) */
int MaxSum = 0;
/* ... */
MaxSum = MaxSubsequenceSum(A, N);





参见< a href =http://www.cplusplus.com/articles/yAqpX9L8/>声明,原型,定义 [ ^ ]



一旦理解并修复了代码,就可以开始修复时间计算(实际上是打印未经过时间计算的值)。



See also Declarations, Prototypes, Definitions[^]

Once you have understand that and fixed your code you can start to fix the time calculations (you are actually printing values that has not been calculated from the elapsed time).


这篇关于如何删除这些错误并计算运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆