if- if_else
if- if_else
Code:
#include<stdio.h>
int main()
{
int a;
printf("Enter an integer number: ");
scanf("%d",&a);
if(a%2 ==0)
{
printf("%d is even number.",a);
}
else
{
printf("%d is odd number.",a);
}
return 0;
}
Output:
2. Write a program that read two integer numbers and display maximum.
Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter the first number: ");
scanf("%d",&a);
printf("Enter the second number: ");
scanf("%d",&b);
if(a>b)
{
printf("%d is maximum.",a);
}
else
{
printf("%d is maximum.",b);
}
return 0;
}
Output:
3. Write a program that read two integer numbers and display minimum.
Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter the first number: ");
scanf("%d",&a);
printf("Enter the second number: ");
scanf("%d",&b);
if(a<b)
{
printf("%d is minimum.",a);
}
else
{
printf("%d is minimum.",b);
}
return 0;
}
Output:
4. Write a program that read three integer numbers and display maximum.
Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the first number: ");
scanf("%d",&a);
printf("Enter the second number: ");
scanf("%d",&b);
printf("Enter the third number: ");
scanf("%d",&c);
if(a>b && a>c)
{
printf("%d is maximum.",a);
}
else if(b>c)
{
printf("%d is maximum.",b);
}
else
{
printf("%d is maximum.",c);
}
return 0;
}
Output:
5. Write a program that read three numbers and display minimum.
Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the first number: ");
scanf("%d",&a);
printf("Enter the second number: ");
scanf("%d",&b);
printf("Enter the third number: ");
scanf("%d",&c);
Output:
6. Write a program that read three numbers and display medium.
Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the first number: ");
scanf("%d",&a);
printf("Enter the second number: ");
scanf("%d",&b);
printf("Enter the third number: ");
scanf("%d",&c);
Output:
7. Write a program that read mark and display pass or fail.
Code:
#include<stdio.h>
int main()
{
double marks;
printf("Enter mark: ");
scanf("%lf",&marks);
Output:
8. Write a program that read mark and display result in division.
Code:
#include<stdio.h>
int main()
{
double marks;
printf("Enter mark: ");
scanf("%lf",&marks);
if(marks < 0 || marks >100 )
{
printf("Enter a valid mark.");
}
else if(marks >=60)
{
printf("First Division");
}
else if(marks >=50 && marks <=59)
{
printf("Second Division");
}
else if(marks >= 40 && marks <=49 )
{
printf("Third Division");
}
else
{
printf("Letter Grade : F");
}
return 0;
}
Output:
9. Write a program that read mark and display result in grade.
Code:
#include<stdio.h>
int main()
{
double marks;
printf("Enter mark: ");
scanf("%lf",&marks);
Output:
10. Write a program that read any year and display leap year or not leap year.
Code:
#include<stdio.h>
int main()
{
int year;
printf("Enter Year: ");
scanf("%d",&year);
if(year % 4 == 0 )
{
if(year % 100 == 0 )
{
if(year % 400 == 0 )
{
printf("%d is Leap Year. ",year);
}
else
{
printf("%d is not a Leap Year.", year);
}
}
else
{
printf("%d is a Leap Year.", year);
}
}
else
{
printf("%d is not a Leap Year.", year);
}
return 0;
}
Output:
11. Write a program that read three numbers (a,b,c) and determine the root of
the quadratic equation:
ax2+bx+c=0
Code:
#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c;
double discriminant;
double root1, root2;
printf("Enter The value of a: ");
scanf("%lf",&a);
printf("Enter The value of b: ");
scanf("%lf",&b);
printf("Enter The value of c: ");
scanf("%lf",&c);
if(a <= 0 )
{
printf("Enter a value of a > 0. ");
}
else
{
discriminant = b*b - 4.0*c*a;
if(discriminant >= 0)
{
root1 = (-b+ sqrt(discriminant)) / (2.0 * a);
root2 = (-b- sqrt(discriminant)) / (2.0 * a);
printf("Root 1: %lf", root1);
printf("\nRoot 2: %lf", root2);
}
else
{
printf("No real Root");
}
}
return 0;
}
Output: