0
{
SumOddEven(A,n)             //A is array and n is size of array
{
    int count, sum;
    for(int i = 1; i<=n; i++)  {
    sum_even=0;
    sum_odd=0;
                    for(int j = i; j<=n; j++)  {
               if (A[j] Mod 2 == 0)                  //check if number is even
                                        sum_even=sum_even+A[j]    //Sum even numbers
                                    else
                                        sum_odd=sum_odd+A[j]      //Sum odd numbers
              }
    cout<<sum_even;
    cout<<sum_odd;
            }
}
5
Contributors
4
Replies
24
Views
1 Year
Discussion Span
Last Post by dannyniu
0

Under Linux you can use the time command to give you the amount of time taken to run a command. To review the manual entry for time use:
man time

TIME(1)                       Linux User's Manual                      TIME(1)

NAME
       time - time a simple command or give resource usage

SYNOPSIS
       time [options] command [arguments...]

DESCRIPTION
       The  time  command  runs  the  specified program command with the given
       arguments.  When command finishes, time writes a  message  to  standard
       error  giving  timing statistics about this program run.  These statis‐
       tics consist of (i) the elapsed real time between invocation and termi‐
0

Did you face a problem or an error in the code given?

If you did, post the error noted here for us to provide our perspective on the problem.

If you want to get an understanding on measuring time complexity, you can refer to the post i have made earlier that relates to this problem at the below link:-
Click Here

0

I suppose it has a run time linear to the size of the input n. I'm no expert on computational complexity, but I've heard some of the concepts.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.