i want it to print out 4 is larger than 2 but it prints out 2 is larger than 2293572

#include <stdio.h>
#include <stdlib.h>

void largest(int num1, int num2, int *larger)
{

if(num1 > num2) {
*larger = num1;
}
else{
*larger = num2;
}
}

int main()
{
int num;
largest(4,2,&num);
printf(" %d is larger %d");
}

> printf(" %d is larger %d");
How many extra parameters do you think printf needs here?

> printf(" %d is larger %d");
How many extra parameters do you think printf needs here?

i added 2 more parameters the num and largest but it still not working or is there something wrong with my function

Well if you added
printf(" %d is larger %d","apple","banana");
then yeah, that wouldn't work either.

Post your ACTUAL CODE if you want an actual answer to what you've done wrong.

that is my actual code i want to pass 2 numbers by value and return a pass by refrence for an answer well here is the question i got

Write a void C function called largest that takes two integers passed by
value and returns the larger of the two using a third integer parameter
which is passed by reference.

#include <stdio.h>
#include <stdlib.h>

void largest(int num1, int num2, int *larger)
{

if(num1 > num2) {
*larger = num1;
}
else{
*larger = num2;
}
}

int main()
{
int num;
largest(4,2,&num);
printf(" %d is larger %d");
}

Weird - your printf statement looks exactly the same, except for the fact that you said you changed it.

Thanks for playing.

commented: i feel your pain +7

i dont understand you

cant you help me

He's trying to help you think by yourself.
It is just an error in your printf() format. You are missing arguments.

printf(" %d is larger %d");

You have two format tags %d but you do not provide specifiers. It should be similar in nature to:

printf("%d is larger than %d", biggernumber, smallernumber);

Telling you more, it is doing it for you. No, no.

besides the fact you're not supplying the promised arguments to your printf statement, you're approaching this in a confused manner.

your function takes two inputs and just outputs the larger of the two. it does NOT comparatively sort the two.

so in keeping with the purpose of the function, you should probably not be trying to print a comparative statement like "%d is larger than %d" , but you should rather be printing the result of the function simply as it is given:

printf("%d is the larger number", <NowIWonderWhatGoesHere>);

thanks for the help guys i must be dumb just startin programming

don't sweat it. i've done more dumb programming things than i care to remember. and i still do :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.