Comparison of Numbers using C Programming Language

Comparison of Numbers:

It means it takes two numbers , after comparing them will tell which number is greater or not.The different signs are used to compare two thins.Greater than , smaller than or in case of equal value equal sign.

Explanation of Program Code:

For input and output streams, include library file stdio.h. printf and scanf are output and input streams respectively.Then add main function in program code which is the necessary function of every C program.
So how many variables to define and about their data type, as comparison is always between the two things so definitely two variables and their data types depends upon the numbers , if they are integers then integer type and if they are decimal numbers then float or double.

Recommended Article: 

Read this article for better understanding of program code.This article is actually for c++ ,, but the basic is same.

Program Code:
 #include<conio.h>
#include<stdio.h>

int main()
{
int num1 , num2;
printf("Enter First number\n");
scanf("%d",&num1);
printf("\n");

printf("Enter Second number\n");
scanf("%d",&num2);
printf("\n");


if(num1 > num2)
printf(" %d is an greater number",num1);

if(num1 == num2)
printf(" Both are eqaul ");

else
printf(" %d is an smaller number",num1);

getch();

}

Output: After compile and run

Hope that you will find this helpful.

1 comment:

  1. Nice to see you moving on to C language.

    ReplyDelete

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.