Skip to main content

Featured

C Program to Solve Two Sum Using Brute Force (With Algorithm & Output)

 Introduction The Two Sum problem is a popular coding interview question where we must find two indices of an array whose values add up to a given target. This program demonstrates a simple brute-force solution in C using nested loops and dynamic memory allocation. Problem Statement Given an integer array and a target value, return the indices of the two numbers such that they add up to the target. Each input has exactly one solution, and the same element cannot be used twice. The result should return the indices, not the values. If no solution exists, return NULL.  Algorithm / Logic Explanation Start the program. Traverse the array using a loop from index 0 to numsSize - 1 . Inside this loop, use another loop starting from i + 1 to numsSize - 1 . For every pair (i, j) , check if nums[i] + nums[j] == target . If condition becomes true: Allocate memory for 2 integers using malloc() . Store indices i and j . Set returnSize = 2 . Return the result poi...

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

๐ŸŒ™