Large Number Program in C language
Large Number Program Description:
This is the program to check the Largest of Two Numbers ( Large Number Program) in the C programming language.
The program will ask for two numbers and display the largest of two.
Expected Output:
Example 1:
Input:
1 |
Enter two numbers: 300 100 |
Output:
1 |
300 is Large number |
Example 2:
Input:
1 |
Enter two numbers: -7 10 |
Output:
1 |
10 is Large Number |
Pre-Requisites:
It is recommended to have the basic Idea about the decision-making statement (like an if-else statement) and the Relational operators in the C language.
You can check the following article to get the desired understanding of the above topics
- https://sillycodes.com/decision-making-or-control-statements-in-c-programming-language/
- https://sillycodes.com/relational-operators-in-c-with-examples/
Large Number Program Explanation:
- At the start, Program will prompt the user for Input, and the User needs to enter two numbers
- We are storing the number is num1 and num2 variables
- Then we are using the if else statement to check whether the num1> num2. If it returns true, Then the num1 is larger than the num2. So we are displaying the num1 as the Large Number
- If the above condition is not true, Then the next condition will be evaluated num1 < num2, If it returns true, Then the num2 is larger than the num1. So We are printing the num2 as Large Number onto the console.
- If the above two conditions returns false, Then the num1 and num2 should be equal to each other. So we are displaying the equal message onto the console.
Large Number Program in C Language:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* Program: Program to check the large Number of two number */ #include<stdio.h> int main() { int num1, num2; printf("Enter two numbers: "); scanf("%d%d", &num1, &num2); // check which number is large if(num1 > num2) { // num1 is larger than num2 printf("%d is Large number\n", num1); } else if (num1 < num2) { // num2 is bigger number printf("%d is Large Number\n", num2); } else { // num1 and num2 are equal printf("num1: %d and num2: %d are equal \n", num1, num2); } return 0; } |
Program Output:
We are using the GCC compiler to compile and run the program. Learn about compiling and running programs in Linux at the following article
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ gcc larger-num.c $ ./a.out Enter two numbers: 300 100 300 is Large number $ ./a.out Enter two numbers: -7 10 10 is Large Number $ ./a.out Enter two numbers: -10 -2 -2 is Large Number $ ./a.out Enter two numbers: 4 4 num1: 4 and num2: 4 are equal $ ./a.out Enter two numbers: 9000 1234 9000 is Large number $ |
Related Programs:
- https://sillycodes.com/c-program-to-check-positive-negative-or-zero/
- https://sillycodes.com/category/c-codes/
3 Responses
[…] C Program to Print the Larger Number of Two Numbers […]
[…] have looked at the Program to find the Maximum of two numbers using the if else statement and conditional statements. In today’s article, We are going to write a C Program to find the […]
[…] C Program to Print the Larger Number of Two Numbers […]