2. #include<stdio.h>
#include<math.h> //for sqrt() function
main()
{
float a,b,c,dis,r1,r2;//a,b,c are constant coefficients, dis= discriminant and r1,r2 are roots
printf ("nQuadratic Equation is of the form: ax^2 + bx + c = 0 n");
printf("nEnter the values of a, b and c: ");
scanf("%f %f %f",&a,&b,&c);
dis = pow(b,2) - 4*a*c; // calculation of discriminant
if(dis < 0) //checking the value of discriminant
{
printf("nThe roots are imaginary.nn");
printf("Root1= %.3f % + .3fi",-b/(2*a),sqrt(-dis)/(2*a));
printf("nRoot2= %.3f %+ .3fin",-b/(2*a),-sqrt(-dis)/(2*a));
}
1. QUADRATIC EQUATION
3. else
{
r1 = (-b + sqrt(dis))/(2.0*a);
r2 = (-b - sqrt(dis))/(2.0*a);
printf("nThe first root is = %fnThe second root is = %fn",r1,r2);
}
return 0;
}
OUTPUT
1. QUADRATIC EQUATION
4. #include<stdio.h>
int main()
{
float fahrenheit, celsius;
//get the limit of fibonacci series
printf("Enter Fahrenheit: n");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %f n", celsius);
return 0;
}
OUTPUT
Enter Fahrenheit:
100
Celsius: 37.777779
2/ FAH TO CEL
This is it, t
5. #include <stdio.h>
int main()
{
double n1, n2, n3;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if (n1>=n2)
{
if(n1>=n3)
printf("%.2lf is the largest number.", n1);
else printf("%.2lf is the largest number.", n3);
}
else
{
if(n2>=n3)
printf("%.2lf is the largest number.", n2);
5. Largest Number
6. else
printf("%.2lf is the largest number.",n3);
}
return 0;
}
OUTPUT
Enter the number : 10,15,20
The largest number is : 20
8. else printf(" (1/%d) + ",i);
}
printf("nn THE SUM OF THIS SERIES IS %.2lf",sum); getch();
}
Output
Please Give The Value of N: 5
1 + (1/2) + (1/3) + (1/4) + (1/5)
THE SUM OF THIS SERIES IS 2.28
9. 8. Leap Year
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
10. 8. Leap Year
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
Output
Enter a year: 1900
1900 is not a leap year.
11. 18. Area of Circle
#include<stdio.h>
int main() {
float radius, area;
printf("nEnter the radius of Circle : ");
scanf("%d", &radius);
area = 3.14 * radius * radius;
printf("nArea of Circle : %f", area);
return (0);
} Output
Enter the radius of Circle : 2.0
Area of Circle : 6.14
12. 14. Factorial
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate it's factorialn");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %dn", n, fact);
return 0;
}