Find larger value between two variable
/* Find larger value between two variable */
#include<stdio.h>
int main()
{
int a,b;
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
if(a>b)
printf("A is larger");
else if(b>a)
printf("B is larger");
else
printf("A and B are equal");
return 0;
}
Largest value of two variables - Conditional Operator
/* Find largest value between two variables - single line - Conditional Operator */
#include<stdio.h>
int main()
{
int a,b,d;
printf("Type values of A and B : ");
scanf("%d %d",&a,&b);
d=(a>=b?a:b);
printf("Greatest value : %d",d);
return 0;
}
#include<stdio.h>
int main()
{
int a,b,d;
printf("Type values of A and B : ");
scanf("%d %d",&a,&b);
d=(a>=b?a:b);
printf("Greatest value : %d",d);
return 0;
}
Largest value among three variables
/* Largest value among three variables */
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
printf("Enter value of c: ");
scanf("%d",&c);
if(a >= b && a >= c)
printf("%d is largest",a);
else if(b >= a && b >= c)
printf("%d is largest",b);
else if(c >= a && c >= b)
printf("%d is largest",c);
return 0;
}
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
printf("Enter value of c: ");
scanf("%d",&c);
if(a >= b && a >= c)
printf("%d is largest",a);
else if(b >= a && b >= c)
printf("%d is largest",b);
else if(c >= a && c >= b)
printf("%d is largest",c);
return 0;
}
Largest among 3 variables using nested if
/* Find largest among 3 variables using nested if */
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter 3 numbers: \n");
scanf("%d %d %d",&a,&b,&c);
if(a>=b)
{
if(a>=c)
printf("%d is largest",a);
else
printf("%d is largest",c);
}
else if(b>=c)
printf("%d is largest",b);
else
printf("%d is largest",c);
return 0;
}
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter 3 numbers: \n");
scanf("%d %d %d",&a,&b,&c);
if(a>=b)
{
if(a>=c)
printf("%d is largest",a);
else
printf("%d is largest",c);
}
else if(b>=c)
printf("%d is largest",b);
else
printf("%d is largest",c);
return 0;
}
Find largest value among three variable - conditional operator
/* Find largest value among three variable using conditional operator */
#include<stdio.h>
int main()
{
int a,b,c,d;
printf("Type values of A,B and C : ");
scanf("%d %d %d",&a,&b,&c);
d=(a>=b?a>=c?a:c:b>=c?b:c);
printf("Greatest value : %d",d);
return 0;
}
#include<stdio.h>
int main()
{
int a,b,c,d;
printf("Type values of A,B and C : ");
scanf("%d %d %d",&a,&b,&c);
d=(a>=b?a>=c?a:c:b>=c?b:c);
printf("Greatest value : %d",d);
return 0;
}
Leap Year
/* Check Leap Year */
#include<stdio.h>
int main()
{
int y;
printf("Enter a year: ");
scanf("%d",&y);
if(y%4==0)
printf("Leap Year");
else
printf("Not a Leap Year");
return 0;
}
#include<stdio.h>
int main()
{
int y;
printf("Enter a year: ");
scanf("%d",&y);
if(y%4==0)
printf("Leap Year");
else
printf("Not a Leap Year");
return 0;
}
Even Odd Number
/* Check a number is even or odd */
#include<stdio.h>
int main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
if(a%2==0)
printf("Even Number");
else
printf("Odd Number");
return 0;
}
#include<stdio.h>
int main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
if(a%2==0)
printf("Even Number");
else
printf("Odd Number");
return 0;
}
Just Give Your Feedback ConversionConversion EmoticonEmoticon