Defining Absolute Values in C Language [Closed]

Asked 1 years ago, Updated 1 years ago, 41 views

Do you want to improve this question?Edit your post to clarify the issue you are trying to resolve by adding details.

Closed 2 years ago.

Two years ago

We wanted to define absolute values in C language, so we defined them as follows:

No matter how many times I compile, there are only errors, so I think something is wrong, but I didn't know what was wrong."I think the first half of the program below, ""int myabs1(intx)"" is correct, but is ""int main(void)"" wrong?"(By the way, I didn't write "inta;a=myabs1();" at first, so I added that, but I still got an error.So I set a=myabs1(x), but it still didn't work.)

int myabs1(intx)
{
    intabs;
    if(x>=0){
        abs = x;
    } else {
        abs=-x;
    }
    returnabs;
}

int main (void)
{
    inta;
  a = myabs1();
    printf("x value is:\n";
    printf("abs=%d",a);

    return 0;
}

c

2022-09-30 21:48

2 Answers

In , creating your own function myabs1(int) will not run unless you call it correctly.Your myabs1 is designed to take one argument of int, so

inta=-3;
intb = myabs1(a);
printf("a=%db=%d\n", a,b);

x in int myabs1(int x){...} is an algebraic