The Larger Of Two Numbers
C plan to find largest of two given numbers is discussed here. Input 2 integers from the user and find the largest number among them. Given two numbers num1 and num2. The task is to find the largest number amidst the 2.
Example,
Input: num1 = 2, num1 = viii Output: Largest number = 8 Input: num1 = 20, num1 = xviii Output: Largest number = twenty
Algorithm to find the greatest of 2 numbers
- Ask the user to enter ii integer values.
- Read the two integer values in num1 and num2 (integer variables).
- Check if num1 is greater than num2.
- If true, then impress 'num1' equally the greatest number.
- If false, and then impress 'num2' equally the greatest number.
Beneath is the C programme to find the largest among the two numbers:
Detect the largest of two numbers using the if-else status:
#include <stdio.h> int main() { int num1, num2; // Ask user to enter the ii numbers printf("Please Enter Two unlike values\north"); // Read ii numbers from the user scanf("%d %d", &num1, &num2); if(num1 > num2) { printf("%d is Largest\north", num1); } else if (num2 > num1) { printf("%d is Largest\due north", num2); } else { printf("Both are Equal\n"); } return 0; } Output:
Please Enter Two unlike values: 27 6
27 is Largest
Watch this video to see how to find the largest of two given numbers using the C programme.
Find the largest of 2 given number using ternary condition:
#include <stdio.h> int chief() { int num1, num2; // Ask user to enter the two numbers printf("Please Enter Two unlike values\northward"); // Read two numbers from the user scanf("%d %d", &num1, &num2); (num1 >= num2)?((num1 ==num2)?printf("Both numbers are equal"):printf("%d is Largest\n", num1)):printf("%d is Largest\north", num2); return 0; } Output:
Please Enter Two different values 6 6
Both numbers are equal
Recommended Post for you:
- C programme to find the largest of iii given numbers
- C program to find the factorial of a number
- C Plan to swap 2 nibbles in a byte
- C Program to find first and concluding digit of a given number
- C programme to discover even and odd numbers
- C Programme to detect the sum of natural numbers up to n terms
- C Programme to find the sum of fifty-fifty natural numbers from 1 to north
- C Plan to find the sum of odd natural numbers from 1 to n
- C Programme to notice if given number is sum of first n natural numbers
- C program to find sum of beginning and terminal digit of a Number
- C programme to notice the sum of digits of a number
- C program to check leap year
- C program to check valid engagement (appointment is valid or non)
- C program to Check expiry appointment
- C program to find reverse of a number using recursion
- C program to contrary digits of an integer with overflow handled
The Larger Of Two Numbers,
Source: https://aticleworld.com/c-program-to-find-largest-of-two-given-numbers/
Posted by: gerbersuppin.blogspot.com

0 Response to "The Larger Of Two Numbers"
Post a Comment