Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

Find Greatest of Three Numbers in C

Find Greatest of Three Numbers in C

✅ Find the Greatest of Three Numbers in C

#include <stdio.h>

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

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

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

    return 0;
}
  

๐Ÿ“˜ Explanation:

This C program takes three integers as input and determines the greatest among them using simple conditional statements. It compares the three numbers using nested if-else blocks:

  • First checks if a is greater than or equal to both b and c.
  • If not, then checks if b is greater than or equal to the other two.
  • If both conditions fail, then c is the greatest by default.
This approach ensures correct output even if the numbers are equal.

๐Ÿงพ Sample Output:

Enter three numbers:
12 45 33
The greatest number is: 45
  

๐Ÿ”‘ Keywords:

Greatest of three numbers, if else in C, compare numbers in C, logic building in C, beginner level C program, C programming basics

๐Ÿ“Œ Hashtags:

#CProgramming #BeginnerC #MaxOfThree #ComparisonLogic #IfElseC #CodingBasics

Comments

Popular Posts

๐ŸŒ™