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...

WAP to find the max of two numbers

 Description : 

You have to read two integers from user and find the maximum of two integers.

Sample Execution : 

Test case 1 :  

Enter the num1 : 10

Enter the num2 : 20 

Max of two numbers is 20 

Test case 2 :

Enter the num1 : 95

Enter the num2 : 25 

Max of two numbers is 95

PROGRAM:

-----------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
    int num1,num2;
      printf("Enter the num1:");
     scanf("%d",&num1);
    
    printf("Enter the num2:");
    scanf("%d",&num2);
     
     if(num1>=num2)
    {
    printf("max of two numbers is %d",num1);
    
}
else if(num2>=num1)
{
printf("max of two numbers is %d",num2);
}


-----------------------------------------------------------------------------------------------------------------------------

sample input;

Enter the num1:10
Enter the num2:20

sample output:

max of two numbers is 20

Comments

Popular Posts

🌙