C Program logics to find the largest of two numbers


Using this program you can find the largest among two numbers. Here we carry out this by two different logics.



LOGIC 1 (Conditional Operator)

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd number: ");
scanf("%d",&b);
c=a>b?a:b;
printf("The largest number is %d",c);
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub
LOGIC 2 (If Else statement)

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd number: ");
scanf("%d",&b);
if(a>b)
printf("The largest number is %d",a);
else
printf("The largest number is %d",b);
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments