Thursday, November 26, 2020

Write a C program to check whether two numbers in a pair is in ascending order or descending order.

 /*Write a C program to check 

whether two numbers in a pair 

is in ascending order or 

descending order.

Test Data :

Input a pair of numbers (for 

example 10,2 : 2,10):

Input first number of the 

pair: 10

Expected Output:

Input second number of the 

pair: 2

The pair is in descending 

order!

*/

#include <stdio.h>

int main()

{

  int num1,num2,i;

  printf("Input a pair of num\

bers\n(for example 10,2 : 2,\

10): \n");

  printf("Input first number\

 of the pair: ");

  scanf("%d",&num1);

  printf("Input second number\

 of the pair: ");

  scanf("%d",&num2);

  for(i=1;i<num2;i++)

  {

    if(num1>num2)

    {

      printf("The pair is in\

 descending order!\n"); 

    }

    else

    {

      printf("The pair is in\

 ascending order!\n");

      break;

    }

  }

  return 0;

}

No comments:

Post a Comment