I want to find the maximum value of two numbers, and print it. I want to print all three numbers. I am using the following code.
#include<stdio.h>
#include<conio.h>
main()
{
//clrscr();
int a,b,c;
printf("insert two numbers:");
scanf("%d%d", &a, &b);
c = (a>b) ? a : b;
printf("\nmaximum of %d",a," and %d",b," is = %d" c);
getch();
}
However, I receive two syntax errors (Please find the attached figure). Could anybody help me out with it?
There are following methods to print multiple variables, Method 1: Passing multiple variables as arguments separating them by commas. Method 2: Using format() method with curly braces ({}) Method 3: Using format() method with numbers in curly braces ({0})
The first parameter is fixed and is the format string. It includes text to be printed literaly and marks to be replaced by the text obtained from the additional parameters. Thus, printf is invoked with as many parameters as marks are included in the format string, plus one (the format string itself).
To print a percent-sign character, use %%. For non decimal floating-point numbers, signed value having the form [-]0xh. hhhhp[sign]ddd, where h is a single hexadecimal digit, hhhh is one or more hexadecimal digits, ddd is one or more decimal digits, and sign is + or -.
The following line shows how to output the value of a variable using printf. printf("%d", b); The %d is a placeholder that will be replaced by the value of the variable b when the printf statement is executed. Often, you will want to embed the value within some other words.
Change the line where you print the output to:
printf("\nmaximum of %d and %d is = %d",a,b,c);
See the docs here
printf("\nmaximum of %d and %d is = %d",a,b,c);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With