0% found this document useful (0 votes)
25 views

C Program Final

The document describes a C program to solve quadratic equations. It provides the algorithm to calculate the discriminant and determine the number and type of roots. The program code includes functions to input coefficients, calculate the discriminant, and output the appropriate roots. The program is tested and able to correctly solve quadratic equations of all types.

Uploaded by

indhumathi s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

C Program Final

The document describes a C program to solve quadratic equations. It provides the algorithm to calculate the discriminant and determine the number and type of roots. The program code includes functions to input coefficients, calculate the discriminant, and output the appropriate roots. The program is tested and able to correctly solve quadratic equations of all types.

Uploaded by

indhumathi s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Ex.

No : 1 Date :

SOLUTION OF QUADRATIC EQUATION


AIM:
To write C language program to find the solution of quadratic equation.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Read a,b,c values.
STEP 3: Calculate det= b*b-4*a*c.
STEP 4: If d>0 ,then rl=(-b+sqrt(det))/(2*a) , r2=(-b-sqrt(det))/(2*a)
STEP 5: Otherwise if det =0,then rl=r2==-b/2*a .
STEP 6: Print the result.
STEP 7: Stop the program.

PROGRAM CODE:

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
int a,b,c;
float det,r1,r2,rp,ip;
clrscr();
printf(“Enter the valuesof a,b,c\n”);
scanf(“%d%d%d”,&a,&b,&c);
det=b*b-4*a*c;
if(det>0)
{
rl=(-b+sqrt(det))/(2*a);
r2=(-b-sqrt(det))/(2*a);
printf(“\nroot1=%7.3f and root2=%7.3f”,rl,r2);
}
else if(det==0)
{
rl=-b/2*a;
printf(“\nroot1=root2=%7.3f”,r1);
}
else
{
rp=-b/(2*a);
ip=sqrt(-det)/(2*a);
printf(“\nroot1=%7.3f+%7.3fi and root2=%7.3f-%7.3fi”,rp,ip,rp,ip);
getch();
}

RESULT:
Thus the program to find the solution of a quadratic equation has been done
and verified.

POSITIVE OR NEGATIVE
#include<stdio.h>
#include<conio.h>
void main( )
{
int n;
clrscr();
printf(“Enter the value of n:\n”);
scanf(“%d”,&n);
if(n>0)
{
printf(“Positive number\n”);
}
else if(n<0)
{
printf(“Negative number\n”);
}
else
{
printf(“The number is zero”);
}
getch( );
}

SUM OF SERIES(1+2+3+….+N)
#include<stdio.h>
#include<conio.h>
void main( )
{
int i=1,sum=0,n;
clrscr();
printf(“Enter the value\n”);
scanf(“%d”,&n);
while(i<=n)
{
sum=sum+i;
i=i+1;
}
printf(“The sum of series is:%d\t”,sum);
getch( );
}

ARITHMETIC OPERATIONS
#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c,n;
clrscr( );
printf(“Enter the a and b value:\n”);
scanf(“%d%d”,&a,&b);
d:printf(“(Enter your choice :\n”);
printf(“1.add\n2.subtract\n3multiply\n4.divide\n”);
scanf(“%d”,&n);
switch(n)
{
case 1:
c=a+b;
break;
case2:
c=a-b;
break;
case 3:
c=a*b;
break;
case 4:
c=a/b;
break;
default:
printf(“Enter number between 1 to 4\n”);
goto d;
}
printf(“The answer is %d”,c);
getch( );
}

MATRIX ADDITION
#include<stdio.h>
#include<conio.h>
void main( )
{
int a[3] [3],b[3][3],c[3][3];
int i,j;
clrscr( );
printf(“Enter the first matrix :\n”);
for(i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“enter the second matrix:\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf(“new addition matrix:\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\n”);
}
getch( );
}

FACTORIAL USING FUNCTION


#include<stdio.h>
#include<conio.h>
void main( )
{
int fact(int);
inta,n;
clrscr( );
printf(“Enter any integer number\n”);
scanf(“%d”,&n);
a=fact(n);
printf(“The factorial of n=%d”,a);
getch( );
}
int fact(int n)
{
int value,i;
value=1;
if(n==0)
return(value);
else
value=n*fact(n-1);
return(value);
}

PRINT THE STUDENT DETAILS


#include<stdio.h>
#include<conio.h>
struct student
{
int regno;
char name[20];
int mark[10];
int total;
};
void main( )
{
struct student s[100];
int i,j,n;
clrscr( );
printf(“\nEnter the number of student\n”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“\nEnter the register number,name and six marks one by one\n”);
scanf(“%d%s”,&s[i].regno,s[i].name);
for(j=0;j<6;j++)
{
scanf(“%d”,&s[i].mark[j]);
}
}
for(i=0;i<n;i++)
{
s[i].total=0;
for(j=0;j<6;j++)
{
s[i].total=s[i].total+s[i].mark[j];
}
printf(“%d\t%s\t%d\n”,s[i].regno,s[i].name,s[i].total);
}
getch( );
}

CALCULATE THE EQUIVALENT RESISTANCE

#include<stdio.h>
#include<conio.h>
void main( )
{
float r1,r2,r3,rs,rp;
clrscr( );
printf(“\n Enter the value of r1,r2,r3:”);
scanf(“%f %f %f”,&r1,&r2,&r3);
rs=r1+r2+r3;
rp=1/(l/rl+l/r2+l/r3);
printf(“\n Equivalent resistance in series:%f”,rs);
printf(“\n Equivalent resistance in parallel:%f”,rp);
getch();
}

DISPLAY AVERAGE,RMSVALUE,FORM FACTOR,CREST FACTOR


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
float vm,vavg,vrms,Ff,Cf;
printf(“Enter the peak value vm:”);
scanf(“%f”,&vm);
vavg=(0.637*vm);
vrms=(0.707*vm);
Ff=(vrms/vavg);
Cf=(vm/vrms);
printf(“vavg is :%f”,vavg);
printf(“vrms is :%f”,vrms);
printf(“Ff is:%f”,Ff);
printf(“Cf is :%f”,Cf);
getch( );
}

TO FIND ARITHMETIC MEAN,DEVIATION,RANGE,AND STANDARD


DEVIATION
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
int n,i;
float a[100],Am,dev,range,sd,sum,min,max;
clrscr( );
printf(“enter the values of n\n”);
scanf(“%d”,&n);
printf(“enter the %d real number\n”,n);
/*TO FIND AM*/
Sum=0.0;
for(i=0;i<n;i++)
{
scanf(“%f”,&a[i]);
Sum=sum+a[i];
}
Am=sum/n;
/*TO FIND DEVIATION*/

Sum=0.0;

/*DEVIATION**/
for(i=0;i<n;i++)
{
Sum+=a[i]-Am;
}
dev=sum/n;
/*TO FIND RANGE*/
Max=a[0];
Min=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
range=max-min;
/*TO FIND STANDARD DEVIATION*/
Sum=0.0;
for(i=0;i<n;i++)
{
Sum+=(a[i]-Am)*(a[i]-Am);
}
sd= sqrt(sum/n);
printf(“\n \n arithmetic mean,\n\n=%6.3f,\n\n dev,\n\n=%6.3f,\n\nrange,\n\n
=%6.3f,\n\n sd,\n\n=%6.3f”,Am,dev,range,sd);
getch( );
}

CELSIUS TO FAHRENHEIT USING FUNCTION

#include<stdio.h>
#include<conio.h>
void main()
{
int F(int);
inta,c;
clrscr( );
printf(“enter the Celsius value c\n”);
scanf(“%d”,&c);
a=F(c);
printf(“The Fahrenheit of c=%d”,a);
getch( );
}
IntF(int c)
{
int F;
F=(c*1.8)+32;
return (F);
}
SWAP THE TWO VARAIABLES USING POINTER

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,*p,*q,temp;
clrscr( );
p=&a;
q=&b;
printf(“enter the two numbers \n”);
scanf(“%d%d”,&a,&b);
printf(“Before Swapping\t%d\t%d\n”,p,q);
temp=*p;
*p=*q;
*q=temp;
printf(“After Swapping\t%d\t%d\n”,*p,*q);
getch( );
}

You might also like