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 Reverse a Number and Preserve Trailing Zeros

๐Ÿ” C Program to Reverse a Number and Preserve Trailing Zeros

#include<stdio.h>
int main( )
{
    int num,reverse=0,original,zero=0,remainder;
    printf("Enter the number:\n");
    scanf("%d",&num);
    original=num;
    while(original%10==0&&original!=0)
    {
        zero++;
        original=original/10;
    }
    while(num!=0)
    {
        remainder=num%10;
        reverse=reverse*10+remainder;
        num=num/10;
    }
    printf("Reversed Number is:%d",reverse);
    for(int i=0;i<zero;i++)
    {
        printf("0");
    }
    printf("\n");
}
  

๐Ÿ“ Explanation:

This program reverses a number while preserving its trailing zeros. For example, 54000 becomes 45 followed by three zeros → Reversed Number is: 45 000.

๐Ÿ’ก Sample Output:

Enter the number:
54000
Reversed Number is:45 000
  

๐Ÿ” Keywords:

reverse number in C, trailing zeros in reverse, reverse integer with zeros, C programming reverse digits, C reverse number program

Comments

Popular Posts

๐ŸŒ™