You can do
#define new_max(x,y) (((x) >= (y)) ? (x) : (y))
#define new_min(x,y) (((x) <= (y)) ? (x) : (y))
valter
Answer from γηράσκω δ' αεί πολλά διδασκόμε on Stack Overfloww3resource
w3resource.com › c-programming-exercises › pointer › c-pointer-exercise-6.php
C Program: Find the maximum number between two numbers - w3resource
#include <stdio.h> #include <stdlib.h> int main() { int fno, sno, *ptr1 = &fno, *ptr2 = &sno; printf("\n\n Pointer : Find the maximum number between two numbers :\n"); printf("------------------------------------------------------------\n"); printf(" Input the first number : "); scanf("%d", ptr1); // Read the first number from the user and store it using ptr1 printf(" Input the second number : "); scanf("%d", ptr2); // Read the second number from the user and store it using ptr2 // Compare the values pointed by ptr1 and ptr2 to find the maximum number if (*ptr1 > *ptr2) { printf("\n\n %d is the maximum number.\n\n", *ptr1); // Print the maximum number } else { printf("\n\n %d is the maximum number.\n\n", *ptr2); // Print the maximum number } return 0; }
Techcrashcourse
techcrashcourse.com › 2015 › 11 › c-program-maximum-two-numbers-ternary-operator.html
C Program to Find Maximum of Two Numbers
We will first take two numbers as input from user using scanf function. Then we print the maximum number on screen. ... The algorithm begins by taking two numbers, num1 and num2, as input. It then compares the two numbers using an if statement. If num1 is greater than num2, it assigns the value of num1 to the variable max.
1.21- C Program To Find Largest Between Two Numbers By ...
- YouTube
07:12
Program to find maximum and minimum of two numbers without using ...
09:51
HOW TO FIND MAXIMUM BETWEEN TWO NUMBERS || C PROGRAMMING - YouTube
07:12
find maximum between two number using if else - ( c program ) - ...
06:57
Programming Interview: Max and Min of two numbers without Branching ...
Allbca
dreamstudy.allbca.com › c19.html
'C' Larger of 2 num.(by Function)
//Find Larger of two num. using Function #include<stdio.h> #include<conio.h> int max(int a,int b); main() { int x,y; printf("Enter any two number:"); scanf("%d%d",&x,&y); max(x,y); } int max(int a,int b) { if(a>b) printf("A is greater"); else printf("B is greater"); getch(); } ... Here,we will ...
IncludeHelp
includehelp.com › code-snippets › c-program-to-define-macro-to-find-maximum-of-two-numbers.aspx
C program to define Macro to find maximum of two numbers - IncludeHelp
The code segment ((x>y)?x:y) will be replaced as ((a>b)?a:b) (a and b are the actual arguments in the below written program) instead of Macro calling MAX(a,b). ... #include <stdio.h> #define MAX(x,y) ((x>y)?x:y) int main() { int a,b,max; printf("Enter first number: "); scanf("%d",&a); printf("Enter second number: "); scanf("%d",&b); max=MAX(a,b); printf("Maximum number is: %d\n",max); return 0; }
Top answer 1 of 3
15
You can do
#define new_max(x,y) (((x) >= (y)) ? (x) : (y))
#define new_min(x,y) (((x) <= (y)) ? (x) : (y))
valter
2 of 3
0
You can easily write your own function using comparison operators such as >, <, >=, <=, and ==.
Here is an example from this site:
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);//get two int values from user
if (a < b)//is a less than b?
printf("%d is less than %d\n", a, b);
if (a == b)//is a equal to b?
printf("%d is equal to %d\n", a, b);
if (a > b)//is a greater than b?
printf("%d is greater than %d\n", a, b);
return 0;
}
You can use this knowledge to do a simple function that follows this pseudo code:
//get a and b int variable
//is a greater than or equal to b?
//return a
//else
//return b
Some other useful resources:
http://c.comsci.us/tutorial/icomp.html
http://www.cyberciti.biz/faq/if-else-statement-in-c-program/
w3resource
w3resource.com › c-programming-exercises › c-snippets › c-program-to-define-macro-to-find-maximum-minimum-of-two-numbers.php
C – Macro to find maximum/minimum of two numbers
# include <stdio.h> #define MAX(x, y) ((x) > (y) ? (x) : (y)) #define MIN(x, y) ((x) < (y) ? (x) : (y)) int main() { int a = 45, b = 34; printf("The Maximum of %d and %d is %d\n", a, b, MAX(a, b)); printf("The Minimum of %d and %d is %d\n", a, b, MIN(a, b)); return 0; } ... In the above code, the MAX and MIN macros are defined using the ternary operator to check which of the two numbers is larger or smaller.
myCompiler
mycompiler.io › view › CiMQGT0n5Uh
Write a C program to find maximum between two numbers using conditional operator (C) - myCompiler
Copy link Download Share on Facebook Share on Twitter Share on Reddit Embed on website · #include <stdio.h> int a,b; int main() { scanf("%d %d ",&a,&b); if(a>b){ printf("a is grater of two number"); } else{ printf("b is grater of two number"); } return 0; } Output ·
CodeCrucks
codecrucks.com › home › programs › c program to find maximum of two numbers
C Program to Find Maximum of Two Numbers - CodeCrucks
March 21, 2023 - //WAP to find the maximum of the 2 numbers #include <stdio.h> int main() { int n1, n2; printf("Enter the number 1 :--> "); scanf("%d", &n1); printf("Enter the number 2 :--> "); scanf("%d", &n2); if(n1 > n2) { printf("\nThe largest number among %d and %d is %d", n1, n2, n1); } else { printf("\nThe largest number among %d and %d is %d", n1, n2, n2); } return 0; }
Tutorialsinhand
tutorialsinhand.com › tutorials › c-programs › c-conditional-programs › c-program-to-find-the-max-of-2-number.aspx
C program to find the maximum of two number
December 14, 2019 - C program to find the maximum of two number
Aticleworld
aticleworld.com › home › c program to find largest of two given numbers
C program to find largest of two given numbers - Aticleworld
December 25, 2023 - Read the two integer values in num1 and num2 (integer variables). Check if num1 is greater than num2. If true, then print ‘num1’ as the greatest number. If false, then print ‘num2’ as the greatest number. Using if-else Statement. Using ternary operator. Using macros. Using Bit-wise Operator. Let’s discuss each of ...
Learn Java
javatutoring.com › c-program-find-maximum-between-two-numbers
C Program Find Maximum Between Two Numbers | C Programs
November 26, 2025 - Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself. ... As we are discussing in this blog, a maximum number between two numbers is decided based on their absolute value.
myCompiler
mycompiler.io › view › 68tvfxkuRh2
c program to find greatest of two numbers (C) - myCompiler
Copy link Download Share on Facebook Share on Twitter Share on Reddit Embed on website · #include <stdio.h> int main() { int x,y; printf("Enter the two numbers \n"); scanf("%d%d",&x,&y); if(x>y) { printf("x is greater than y\n"); }else { printf("y is greater than x\n"); } } Output ·
w3resource
w3resource.com › c-programming-exercises › inline_function › c-inline-function-exercise-4.php
C inline function - Compute the maximum of two integers
#include <stdio.h> inline int max(int ... 0; } ... In the above program, we define an inline function max() that takes two integers x and y as parameters and returns the maximum value between them....
Brainly
brainly.in › english › secondary school
Write a C program to find maximum of two numbers using conditional operator ?#include #include void main(){ - Brainly.in
December 26, 2022 - /* Take two numbers as input from user · using scanf function */ printf("Enter Two Integers\n"); scanf("%d %d", &a, &b); if(a == b){ printf("Both Equal\n"); return 0; } /* Finds maximum using Ternary Operator */ maximum = (a > b) ? a : b; printf("%d is Maximum\n", maximum); return 0; } Advertisement · Advertisement · Describe the characteristics of Buddhist system of India ·