C programming- Conditional Program
1. TO CHECK WHETHER GIVEN NUMBER IS POSITIVE OR NEGATIVE
#include <stdio.h>
int main()
{
int n;
printf("ENTER ANY NUMBER");
scanf("%d",&n);
if (n>0)
{
printf("%d is positive number",n);
}
else {
printf("%d is negative number",n);
}
return 0;
}
2. TO CHECK WHETHER GIVEN NUMBER IS POSITIVE, NEGATIVE OR ZERO.
#include <stdio.h>
int main()
{
int n;
printf("ENTER ANY NUMBER");
scanf("%d",&n);
if (n>0)
{
printf("%d is positive number",n);
}
else if (n<0)
{
printf("%d is negative number",n);
}
else
{
printf("%d is zero",n);
}
return 0;
}
3.TO FIND THE SMALLEST NUMBER AMONG ANY TWO DIFFERENT NUMBERS
#include <stdio.h>
int main()
{
int a,b;
printf("Enter two numbers");
scanf("%d %d",&a,&b);
if (a<b)
{
printf("%d is smaller than %d",a,b);
}
else
{
printf ("%d is smaller than %d",b,a);
}
return 0;
}
4. TO FIND THE GREATEST NUMBER AMONG ANY THREE DIFFERENT NUMBERS
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter three numbers");
scanf("%d %d %d",&a,&b,&c);
if (a>b && a>c )
{
printf("%d is greatest",a);
}
else if (b>a && b>c)
{
printf ("%d is greatest",b);
}
else
{
printf ("%d is greatest",c);
}
return 0;
}
5. TO FIND THE MIDDLE NUMBER AMONG ANY THREE DIFFERENT NUMBERS
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter three numbers");
scanf("%d %d %d",&a,&b,&c);
if ((a>b && a<c)||(a<b && a>c))
{
printf("%d is middle number",a);
}
else if ((b>a && b<c)||(b<a && b>c))
{
printf ("%d is middle number",b);
}
else
{
printf ("%d is middle number",c);
}
return 0;
}
6. TO TEST GIVEN NUMBER IS EXACTLY DIVISIBLE BY 7 OR NOT.
#include <stdio.h>
int main()
{
int n, r;
printf("Enter a numbers");
scanf("%d",&n);
r=n%7;
if (r==0)
{
printf("%d is exactly divisible by 7",n);
}
else
{
printf("%d is not exactly divisible by 7",n);
}
return 0;
}
7. TO TEST GIVEN NUMBER IS ODD OR EVEN.
#include <stdio.h>
int main()
{
int n, r;
printf("Enter a numbers");
scanf("%d",&n);
r=n%2;
if (r==0)
{
printf("%d is even number",n);
}
else
{
printf("%d is odd number",n);
}
return 0;
}
8. TO CHECK WHETHER CITIZEN CAN VOTE OR NOT(IF VOTING AGE IS 18)
9. TO CHECK WHETHER STUDENT IS PASS OR FAIL IN ECONOMICS(IF PASS MARKS IS 35)
10.TO FIND WHETHER A GIVEN YEAR IS A LEAP YEAR OR NOT.