Skip to main content

Featured

Merge Sort in C++

  Merge Sort in C++ Introduction Merge Sort is a popular sorting algorithm that follows the Divide and Conquer approach. It divides an array into smaller subarrays, recursively sorts those subarrays, and finally merges the sorted subarrays to produce a completely sorted array. In this tutorial, we will learn how to implement Merge Sort in C++ . The program divides the array into two halves using the mid index, recursively sorts both halves, and then combines them using the merge() function. Merge Sort has a time complexity of O(n log n) in the best, average, and worst cases. Table of Contents Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Keywords Conclusion Algorithm Start the program. Read the size of the array. Read the array elements from the user. Call the mer...

C Program to Print Descending Number Pattern Using Loops

Descending Number Pattern in C

Descending Number Pattern in C

This C program prints a number pattern where each row contains numbers in ascending order, but the total number of elements decreases with each row. This is done using nested for loops.

✅ C Program Code:


#include <stdio.h>

int main()
{
    int num;
    printf("Enter the number:\n");
    scanf("%d", &num);
    for (int i = num; i >= 1; i--)
    {
        for (int j = 1; j <= i; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}
  

💡 Explanation:

  • User Input: The program asks for a number (e.g., 5).
  • Outer Loop: Runs from the input number down to 1.
  • Inner Loop: Prints numbers from 1 to the current value of i.

💻 Sample Output:

Enter the number:
5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

🔍 Keywords:

C pattern program, descending number pattern in C, reverse triangle pattern C, number logic in C, beginner friendly C programs, nested loop patterns

Comments

Popular Posts

🌙