Which approach is better - More conditions or More Variables?

multiple independent variables
manipulated independent variable examples
examples of independent variables that cannot be manipulated
multiple dependent variables
how many dependent variables can you have
between-subject factorial design
two independent variables and one dependent variable examples
within-subjects factorial design

I had to write one function to get the largest among four numbers. I find two ways to do that -

#include <stdio.h>                                                        
int main() 
{
    int a, b, c, d;
    int max_of_four(int a, int b, int c, int d);
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int ans = max_of_four(a, b, c, d);
    printf("%d", ans);
    return 0;
}

int max_of_four(int a,int b,int c,int d)
{
    int result,result2,result3;
    if(a>b)
        result=a;
    else
        result=b;
    if(result>c)
        result2=result;
    else
        result2=c;
    if(result2>d)
        result3=result2;
    else
        result3=d;
    return result3;
}

Or I can write the function like this also -

int max_of_four(int a,int b,int c,int d) 
{
    int greatest_int;
    if (a>b && a>c && a>d)
        greatest_int=a;
    else if (b>c && b>d)
        greatest_int=b;
    else if (c>d)
        greatest_int=c;
    else
        greatest_int=d;

    return greatest_int;
}

May I know which would be the better as in the first function I am using more variables and in the next one I am using more conditions. I tried running both & they are taking same amount of time so I couldn't differentiate between the two. As I am just starting with programming with C it would be good to know this as I go forward. Thank You.


Which approach is better - More conditions or More Variables?

First you need to define what you mean by better

Is it better performance?

Is it less memory usage?

Is it better maintenance?

Guessing about performance by looking at the C code is something that you shouldn't do - especially when being new to C. The compiler makes all kinds of optimizations on your C code, so there is (nearly) no way to predict performance. The only solution is to profile.

The same apply to memory usage - even though you define some variables, the compiler is likely to optimize them away. You'll have to inspect the generated assembler code to get an answer.

Regarding maintenance - in nearly all cases this is where you should focus. Make sure that your code is easy to understand (and their by to maintain). Performance issues come second.

Let's look at this code:

int max_of_four(int a,int b,int c,int d)
{
    int result,result2,result3;
    if(a>b)
        result=a;
    else
        result=b;
    if(result>c)
        result2=result;
    else
        result2=c;
    if(result2>d)
        result3=result2;
    else
        result3=d;
    return result3;
}

Here you say that you worry about the number of variables...

Well let's rewrite the code - let's pretend I'm a compiler.

The first thing I notice is that once result is initialized, the variable a isn't used anymore. So why introduce a new variable result when I have a available already. So instead of result I simply use a and rewrite to:

int max_of_four(int a,int b,int c,int d)
{
    int result2,result3;
    if(a>b)
        a=a;
    else
        a=b;
    if(a>c)
        result2=a;
    else
        result2=c;
    if(result2>d)
        result3=result2;
    else
        result3=d;
    return result3;
}

Now the first if is rather strange, so I rewrite to:

int max_of_four(int a,int b,int c,int d)
{
    int result2,result3;
    if(b >= a) a=b;
    if(a>c)
        result2=a;
    else
        result2=c;
    if(result2>d)
        result3=result2;
    else
        result3=d;
    return result3;
}

Once again I notice that once result2 is initialized, the variable a isn't used anymore. So I can repeat the pattern from above and get rid of result2 by replacing it by a. After that I can repeat the same pattern to get rid of result3 and my code looks:

int max_of_four(int a,int b,int c,int d)
{
    if(b >= a) a = b;
    if(c >= a) a = c;
    if(d >= a) a = d;
    return a;
}

Still worried about the number of variables?

Since the compiler can see when the various variables are still in use (or no longer in use), the compiler may optimize your original code just like above by reusing "dead" variables.

But... the compiler will probably do something even more optimal. What? I don't know before I take a look at the generated assembly code.

So the conclusion is - don't look at the C code when finding the better way.

Multiple Independent Variables – Research Methods in Psychology, Researchers' inclusion of multiple independent variables in one experiment By far the most common approach to including multiple independent variables in an experiment is the factorial design. Each combination, then, becomes a condition in the experiment. The study by Schnall and colleagues is a good example. Overview. By far the most common approach to including multiple independent variables in an experiment is the factorial design. In a factorial design A research design with multiple independent variables in which each level of one independent variable is combined with each level of the others to produce all possible conditions., each level of one independent variable (which can also be called


Or you can write this:

int max_of_four(int a,int b,int c,int d) 
{
    int greatest_int = a;
    if (b > greatest_int) {
        greatest_int = b;
    }
    if (c > greatest_int) {
        greatest_int = c;
    }
    if (d > greatest_int) {
        greatest_int = d;
    }
    return greatest_int;
}

Or something like this...

int max_of_four(int a,int b,int c,int d) 
{
    int greatest_int = a;
    int *iter = (int[]){b, c, d}, *end = iter + 3;
    for (; iter < end; iter ++) {
        if (*iter > greatest_int) {
            greatest_int = *iter;
        }
    }
}

Experiment Basics – Research Methods in Psychology, For example, in Darley and Latané's experiment, the independent variable was the number of witnesses that By adding more conditions, the construct validity may not get higher. that it must be done using nonexperimental approaches. Start studying Research Methods Exam 3. Learn vocabulary, terms, and more with flashcards, games, and other study tools.


static int max(int a, int b)
{
    return (a > b) ? a : b;
}

int f(int a, int b, int c, int d)
{
    return max(max(max(a, b), c), d);
}

Types of Research Studies, This approach can also be used to document rare events or conditions that Correlational research can be used to see if two variables are related and to two variables, but the closer the correlation is to -1 or +1, the stronger the correlation is. In the above example, while a research could predict the likelihood of an  Stepwise regression and Best Subsets regression are two of the more common variable selection methods. In this post, I compare how these methods work and which one provides better results. These automatic procedures can be helpful when you have many independent variables and you need some help in the investigative stages of the variable


Is there a method for comparing two techniques measuring the same , Which method(s) can be applied to compare these two techniques? compare two techniques measuring the same variables under multiple conditions. select the best variables before doing PCA, which actually got rid of time and kept the  When fitting (let's say) a linear regression model, it is always true, that the more variables we include in our model, the better fit is (in R^2 sense)? I don't want to discuss here overfitting, problems with diagnostics etc. Just purely mathematical result. Thanks for any input.


How to check statistically whether two or more variables can be , The ultimate validity condition is their subject domain meaning. An alternative approach (in a multiple regression framework) would be to use distance (or its and factors may be made stronger by some combination of two or more factors. Researchers often include multiple independent variables in their experiments. The most common approach is the factorial design, in which each level of one independent variable is combined with each level of the others to create all possible conditions.


Readings in Groupware and Computer-Supported Cooperative Work: , Such a correlational approach requires being able to measure the presence or conditions where X is present (or at a high value), and absent (or low) when X is (X) is higher than the average task performance of the “low liking” groups (X'). For some other variables, such as intelligence or abilities of members, that you​  Choosing a Statistical Test - Two or More Dependent Variables This table is designed to help you choose an appropriate statistical test for data with two or more dependent variables . Hover your mouse over the test name (in the Test column) to see its description.