তিনটি সংখ্যার মধ্যে বড় এবং ছোট সংখ্যা নির্ণয় করার সেরা C প্রোগ্রাম

Learn how to find the largest and smallest number among three using simple C programs. Easy to understand examples with explanations.

C Program, Largest Number, Smallest Number, C Language Basics, C Examples, Programming for Beginners

In the world of programming, learning how to compare numbers is one of the foundational skills. Whether you're developing a game, a calculator, or any kind of decision-based application, being able to determine the largest or smallest among a set of numbers is crucial. In this article, we’ll explore two simple but essential C programs:

  • Finding the largest number among three numbers.
  • Finding the smallest number among three numbers.

These programs are great for beginners who are just getting started with conditional statements and the basics of logic in C.

1. C Program to Find the Largest Number Among Three Numbers

This program uses simple conditional statements (if, else if, else) to compare the three input values and determine which one is the greatest.


#include <stdio.h>

int main() {
    int a, b, c;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    if (a >= b && a >= c) {
        printf("The largest number is: %d\n", a);
    } else if (b >= a && b >= c) {
        printf("The largest number is: %d\n", b);
    } else {
        printf("The largest number is: %d\n", c);
    }

    return 0;
}

Explanation: The program takes three integers as input and compares them using logical conditions. It checks:

  • If a is greater than or equal to both b and c.
  • Else, if b is the greatest.
  • Otherwise, c is the greatest.

Related Posts

2. C Program to Find the Smallest Number Among Three Numbers

This program is similar to the previous one, but this time we are checking for the smallest value among the three inputs.


#include <stdio.h>

int main() {
    int a, b, c;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    if (a <= b && a <= c) {
        printf("The smallest number is: %d\n", a);
    } else if (b <= a && b <= c) {
        printf("The smallest number is: %d\n", b);
    } else {
        printf("The smallest number is: %d\n", c);
    }

    return 0;
}

Explanation: Much like the first program, this one uses logical checks:

  • If a is less than or equal to both b and c.
  • If not, then it checks if b is the smallest.
  • If neither, then c is the smallest.

Conclusion

These two C programs are perfect exercises to practice decision-making with conditional statements. They teach you how to break a problem into smaller logic-based decisions and implement those in code. Once you master this, you’ll be able to solve more complex problems involving comparisons and logic.

Always remember: programming is just like solving puzzles — the more you practice, the better you get. Try expanding these programs by accepting floating-point inputs, or finding both the smallest and largest in a single run!

About the author

Daud
Hey! I'm Daud, Currently Working in IT Company BD. I always like to learn something new and teach others.

Post a Comment

To avoid SPAM, all comments will be moderated before being displayed.
Don't share any personal or sensitive information.