Skip to main content

Featured

C Program to Check Prime Number Using Efficient Logic

  Introduction A prime number is a number that has exactly two distinct positive divisors: 1 and itself. In this program, we check whether a given number is prime or not using a simple and efficient logic. This type of program is commonly used in mathematics, competitive programming, and basic algorithm learning for beginners in C programming. Problem Statement The task is to write a C program that determines whether a given integer is a prime number or not. The program takes a single integer input from the user and analyzes its divisibility. If the number has no divisors other than 1 and itself, it should be identified as a prime number; otherwise, it is not prime. This problem is important in number theory and has practical relevance in areas such as cryptography, data validation, and algorithm design.  Algorithm / Logic Explanation To check whether a number is prime, we need to verify that it is not divisible by any number other than 1 and itself. The algorithm follows a si...

C++ Program Using Inline Function (Square / Multiplication)

C++ Inline Function Example – Square Using Inline Function

C++ Program Using Inline Function (Square / Multiplication)


#include <iostream>
using namespace std;

inline int squar(int a, int b)
{
    return a * b;
}

int main()
{
    int x, y;
    cout << "Enter any two numbers:" << endl;
    cin >> x >> y;
    cout << "the squar of " << x << " and " << y
         << " is " << squar(x, y) << endl;
    return 0;
}
  

๐Ÿ“˜ Explanation:

This program demonstrates the use of an inline function in C++ to perform multiplication of two numbers.

The function squar() is declared using the inline keyword. When this function is called, the compiler attempts to replace the function call with the actual function code to reduce function call overhead.

Inline functions are best suited for small and frequently used functions, as they improve execution speed by avoiding repeated function calls.

๐Ÿงพ Sample Output:

Enter any two numbers:
4 5
the squar of 4 and 5 is 20
  

๐Ÿ”‘ Keywords:

C++ inline function, inline multiplication, C++ square program, inline function example, C++ basics, function optimization

๐Ÿ” Search Description:

Learn how inline functions work in C++ with a simple program that multiplies two numbers. Includes explanation, syntax, and example output.

๐Ÿ“Œ Hashtags:

#CPlusPlus #InlineFunction #CPPBasics #Programming #Coding #1printf

Comments

Popular Posts

๐ŸŒ™