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

C Program To Find Roots of The Quadratic Equation

The C program takes in coefficients a, b, and c of a quadratic equation as input from the user and calculates the two roots of the equation using the quadratic formula. It prints the two roots.

Uploaded by

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

C Program To Find Roots of The Quadratic Equation

The C program takes in coefficients a, b, and c of a quadratic equation as input from the user and calculates the two roots of the equation using the quadratic formula. It prints the two roots.

Uploaded by

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

C program to find roots of the Quadratic Equation

#include <stdio.h>
#include <conio.h>
#include <Math.h>
void main ()
{
float a,b,c,r1,r2;
clrscr();
printf("Enter the coefficients of equations");
scanf("%f %f %f",&a,&b,&c);
r1=(-b+sqrt(b*b-4*a*c))/(2*a);
r2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("\nThe roots of the equation are % f and %f ",r1,r2);
getch();
}

C program to convert these expressions into C


statements
(𝑥+3)𝑥 3
(a) 𝑍 =
(𝑦−4)(𝑦+5)

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
float x,y,z;
clrscr();
printf("\n Enter values for x and y: ");
scanf("%f %f",&x,&y);
z=((x+3)*x*x*x)/((y-4)(y+5));
printf("\n Value of the expression Z=((x+3)*x*x*x)/((y-4)(y+5)): %f",z);
getch();
}
2𝑣+6.22(𝑐+𝑑)
(b) 𝑅 =
𝑔+𝑣

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
float c,d,g,v,r;
clrscr();
printf("\n Enter values for c,d,g and v: ");
scanf("%f %f %f %f",&c,&d,&g,&v);
r=((2*v)+(6.22*(c+d)))/(g+v);
printf("\n Value for the expression R=((2*v)+(6.22(c+d)))/(g+v):
%f",r);
getch();
}

7.7𝑏(𝑥𝑦+𝑎)
𝑐
−0.8+2𝑏
(c) 𝐴 = 1
(𝑥+𝑎)(𝑦)

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
float a,b,c,x,y,A=0;
clrscr();
printf("\n Enter values for a,b,c,x and y: ");
scanf("%f %f %f %f",&a,&b,&c,&x,&y);
A=(((7.7*b*((x*y)+a))/c)-(0.8+(2*b)))/((x+a)*(1/y));
printf("\n Value of expression \n A=(((7.7*b*((x*y)+a))/c)-
(0.8+(2*b)))/((x+a)*(1/y)): %f",A);
getch();
}

Write a program to receive Cartesian co-ordinates


(x,y) of a point and convert them into polar co-
ordinates(r,ⱷ).

𝒚
Hint: 𝒓 = 𝒔𝒒𝒓𝒕(𝒙𝟐 + 𝒚𝟐 )𝒂𝒏𝒅 𝝋 = 𝐭𝐚𝐧−𝟏 ⁄𝒙

#include<conio.h>
#include<stdio.h>
#include<math.h>

void main()
{
float x,y,a,b;
clrscr();

printf("\n Enter the coordinates: ");


scanf("%f %f",&x,&y);

a=sqrt((x*x)+(y*y));
b=atan(y/x);
printf("\n Polar coordinates are: %f and %f",a,b);
getch();
}

Write a program to print ascii value of character.

#include<stdio.h>
#include<conio.h>
void main()
{
char a;
printf("Enter a character ");
scanf("%c", &a);
printf("ASCII value of %c is %d \n ",a ,a);
getch();
}
Write a program to convert lowercase to uppercase
letter using if-else

#include <stdio.h>
#include <conio.h>
void main()
{
char c,ch;
clrscr();
printf("Enter a letter ");
scanf("%c",&c);
if(c>=97 && c<=122)
{
ch=c-32;
printf("The uppercase of %c is %c ",c,ch);
}
else
{
printf("The letter itself is in upper case ");
}
getch();
}
WAP to check whether a number is divisible by 3 and
5 or by 3 or 5.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,flag=0;
clrscr();
printf("Enter a number: \n");
scanf("%d",&n);
if(n%3==0)
flag+=1;
if(n%5==0)
flag+=2;
if(flag==3)
printf("Divisible by both 3 and 5\n");
else if(flag==1)
printf("Only divisible by 3\n");
else if (flag==2)
printf("Only divisible by 5\n");
else
printf("Divisible by none(i.e. 3 and 5)\n");
getch();
}
WAP to enter the marks of a student in 4 subjects.
Calculate total ,aggregate and display the grades.
#include <stdio.h>
#include <conio.h>
void main()
{
float a,b,c,d,t,avg;
clrscr();
printf("Enter the marks in 4 subjects ");
scanf("%f %f %f %f",&a,&b,&c,&d);
t=(a+b+c+d);
avg=((t)/4);
printf("\nTotal marks obtained by the student is %f",t);
printf("\nAverage marks obtained by the student is %f",avg);
printf("\nPercentage obtained by the student is %f",avg);
getch();
}

WAP to check a given number is positive or negative.


#include <stdio.h>
#include <conio.h>
void main()
{
int a;
clrscr();
printf("Enter a number\n");
scanf("%d",&a);
if(a==0)
{
printf("%d is neither positive nor negative \n ",a);
}
else if (a>0)
{
printf("%d is positive \n ",a);
}
else
{
printf("%d is negative \n ",a);
}
getch();
}

WAP to accept the salary of an employee from the


user. Calculate the gross salary on the following
basis:
Basic HRA DA .
1 - 4000 10% 50%
4001 - 8000 20% 60%
8001 - 12000 25% 70%
12000 and above 30% 80%

#include<stdio.h>
#include<conio.h>
void main()
{
float sal,gsal,hra,da;
clrscr();
printf("Enter the salary of the employee \t");
scanf("%f",&sal);
if(sal>=1 && sal <=4000)
{
hra=sal*0.1;
da=0.50*sal;
}
else if(sal>=4001 && sal<=8000)
{
hra=0.20*sal;
da=sal*0.60;
}
else if(sal>=8001 && sal<=12000)
{
hra=0.25*sal;
da=0.70*sal;
}
else
{
hra=0.30*sal;
da=0.80*sal;
}
gsal=sal+hra+da;
printf("The salary is %f \n",sal);
printf("The HRA is %f \n",hra);
printf("The DA is %f \n",da);
printf("The gross salary is %f \n",gsal);
getch();
}
Write a C program to input electricity unit charge
and calculate the total electricity bill according to
the given condition:

For first 50 units Rs. 0.50/unit


For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to
the bill.

#include <stdio.h>
#include <conio.h>
void main()
{
float unit,bill,total;
bill=0;
clrscr();
printf("Enter electricity unit ");
scanf("%f", &unit);
if(unit<=50)
{
bill=unit*0.50;
}
else if(unit<=150)
{
bill=(50)*0.50+(unit-50)*0.75;
}
else if(unit<=250)
{
bill=50*0.50+100*0.75+(unit -150)*1.20;
}
else
{
bill=50*0.50+100*0.75+100*1.20+(unit-250)*1.50;
}
total=bill+0.20*bill;
printf("The electricity bill for %f unit is %f ",unit,total);
getch();
}

You might also like