Monday 26 October 2015

C LANGUAGE PROGRAM TO DECIDE EITHER NUMBER IS LESSER OR GREATER

WRITE A PROGRAM THAT TAKES TWO DIFFERENT NUMBERS AS INPUT FROM USER, AND DECIDE WHICH NUMBER IS LESSER, GREATER OR EQUAL TO OTHER

#include<stdio.h>       // Header file  “Standard Input and Output”
#include<conio.h>      //Header file “Console input and output”
void main ()
{
            clrscr();                                                            // Clear the output screen
            int number1, number2;                                    // Variable declaration
            printf("Enter first number = ");                       // Display prompt for first number
            scanf("%d",&number1);                                  // Take first input from user
            printf("Enter second number = ");                  // Display prompt for first number
            scanf("%d",&number2);                                  // Take second input from user
            if (number1 > number2)                                  // Check number 1 is greater than number 2
                        printf("%d is greater than %d",number1,number2);
            else if (number1 < number2)                           // Check number 1 is less than number 2
                        printf("%d is less than %d",number1,number2);
            else                                                                  // Otherwise the numbers will be equal
                        printf("%d is equal to %d",number1, number2);

getch();
}

OUTPUT

Enter first number = 4
Enter second number = 10
4 is less than 10

Enter first number = 35
Enter second number = 23
35 is greater than 23

Enter first number = 20
Enter second number = 20
20 is equal to 20

EXPLANATION

Multiple If-Else is used and three different conditions are applied in this program. First condition is checking for the greater number, second condition is checking for the lesser number and third condition is used to check the equality of numbers.


Program will test the condition one by one and when the condition is tested successfully the corresponding output will be displayed and program jumps out of the if-else structure, and the program will be end.

Read More

1. What is File Path?
2. How to open hidden files directly?
3. How to rename multiple files in one second?

No comments:

Post a Comment