Code Box
----------------------------------------------
/* Program to Solve Quadratic Equation Using Conditional operator and Switch */
/* In quadratic equation we need values of a,b,c
and D=(b square -4.a.c)
and every thing depends on the value of D
*If D grater than 0 multiple and real root
*If D==0 only single root
*If D is less than 0 than imaginary roots
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,D,n;
float x1,x2,D1;
clrscr();
printf("\nEnter Values");
printf("\n a = ");
scanf("%d",&a);
printf("\n b = ");
scanf("%d",&b);
printf("\n c = ");
scanf("%d",&c);
printf("\nEnterd Values are : a=%d b=%d c=%d",a,b,c);
printf("\nQuadratic Equation Calculation:");
D=(b*b)-(4*a*c);
printf("\nValue of Normal D= %d ",D);
D1=abs(D);
D1=sqrt(D1);
printf("\nValue of Squared D= %.3f ",D1);
n=(D>=0)?(D==0?2:1):3;
printf("\nValue of n : %d",n);
switch(n)
{
case 1:
//Multiple Roots
printf("\nReal & Multiple Roots");
x1=((b+D1)/(2*a));
x2=((b-D1)/(2*a));
printf("\n\nRoots are X1=%.3f X2=%.3f ",x1,x2);
break;
case 2:
//Single Root
printf("\nReal & Single Roots");
x1=((b)/(2*a));
printf("\n\nRoots are X1=%.3f",x1);
break;
case 3:
//Imaginary Part
printf("\nImaginary Roots");
printf("\nX1=(%d+%.3fi)/2*%d",b,D1,a);
printf("\nX2=(%d-%.3fi)/2*%d",b,D1,a);
break;
default:
printf("\nWrong Entry, Error!!!");
}
getch();
}
Code Box
-------------------------------------------
/* Program to convert temperature Fahrenheit to Celsius in C */
#include<conio.h>
#include<stdio.h>
void main()
{
float c,f;
clrscr();
printf("\n\tTEMPERATURE CONVERTER \n\t[Fahrenheit to Celsius]");
printf("\n\tEnter temperature in F:");
scanf("%f",&f);
c=((f-32)*5)/9;
printf("\n\tF= %f equals to C= %f",f,c);
getch();
}
Code Box
----------------------------------------
/*Program to convert temperature Celsius to Fahrenheit in C */
#include<conio.h>
#include<stdio.h>
void main()
{
float c,f;
clrscr();
printf("\n\tTEMPERATURE CONVERTER \n\t[Celsius to Fahrenheit]");
printf("\n\tEnter temperature in C:");
scanf("%f",&c);
f=((c*9)/5)+32;
printf("\n\tC= %f equals to F= %f",c,f);
getch();
}
Code Box
-----------------------------------------------
/*Program to calculate sum of series
1/(1square)+1/(2 square)+1/(3 square)+.......+1/(n square).
by power function.
where n is the value entered by user
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum;
clrscr();
sum=0;
printf("\nEnter limit number : ");
scanf("%d",&n);
printf("\nSeries=");
printf("\n---------------------\n");
for(i=1;i<=n;i++)
{
printf(" +1/(%d*%d) ",i,i);
sum=sum+pow(i,-2); //power function
}
printf("\n---------------------\n");
printf("\nSum of series= %.3f",sum);
getch();
}
Code Box
-----------------------------------------------
/*Program to calculate sum of series
1/1+1/2+1/3+.......+1/n.
by power function.
where n is the value entered by user
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum;
clrscr();
sum=0;
printf("\nEnter limit number : ");
scanf("%d",&n);
printf("\nSeries=");
printf("\n---------------------\n");
for(i=1;i<=n;i++)
{
printf(" +1/%d ",i);
sum=sum+pow(i,-1); //power function
}
printf("\n---------------------\n");
printf("\nSum of series= %.3f",sum);
getch();
}
Code Box
----------------------------------------
/*Program to enter hours and print numbers of days and remaining hours and convert remaining hours into minutes */
#include<stdio.h>
#include<conio.h>
void main()
{
float hours,rhours,min;
/*hours for hours enter by User and rhours for remaining hours */
int days,h;
/*For numbers of Day */
clrscr();
printf("\n\tHours to Day Converter");
printf("\n\tEnter Hours :");
scanf("%f",&hours);
h=hours;
printf("\n\tHours:%d",h);
min=hours-h;
printf("\n\tRemaining Hours:%.2f",min);
min=(min*60);
printf("\n\tMinutes:%.2f",min);
rhours=h%24;
/*Modulus operator provide us the remainder after Division which is remaining hours */
days=(int)hours/24;
/*Division operator to calculate Days as we know 24 hours means 1 Day */
printf("\n\tNumber of Days : %d",days);
printf("\n\tRemaining Hours: %f",rhours);
getch();
}