Showing posts with label Math. Show all posts
Showing posts with label Math. Show all posts

Wednesday, January 5, 2011

Program to find out roots of a quadratic equation

/*  Name: Program to find out roots of a quadratic equation

Author: Parveen Malik

Date: 05/01/11 21:00*/


#include<stdio.h>

#include<conio.h>

#include<math.h>
void main()

{

int a,b,c;

float disc; // Discriminant

float root1,root2;

printf("Enter the value of a,b and c respectively\n");

printf("a = ");

scanf("%d",&a);

printf("b = ");

scanf("%d",&b);

printf("c = ");

scanf("%d",&c);

disc=b*b-4*a*c;

root1=-b+sqrt(disc)/2*a;

root2=-b-sqrt(disc)/2*a;

if(disc==0)

{

printf("Roots are real and equal\n");

printf("First Root :%.2f = Second Root: %.2f\n",root1,root2);

}

else if(disc<0)

{

printf("Roots are imaginary");

printf("First root = %.2f\n",root1);

printf("Second root = %.2f\n",root2);

}

else

{

printf("Roots are real and distinct\n");

printf("First root = %.2f\n",root1);

printf("Second root = %.2f\n",root2);

}

getch();

}

[caption id="attachment_82" align="aligncenter" width="655" caption="OUTPUT"]Program to find out roots of a quadratic equation[/caption]

Monday, January 3, 2011

Program to calculate area of a circle

/*
Name: Program to calculate area of a circle
Author: Parveen Malik
Date: 03/01/11 19:46
*/

#include<stdio.h>
#include<stdio.h>
#define PI 3.141 // to define value of pi


void main()
{
int radius;
float area;

printf("Enter the radius of the Circle : ");
scanf("%d",&radius);

area=PI*radius*radius; // formula to find the area of a circle
printf("\nArea of the Circle is : %.2f",area);

getch();
}
OUTPUT:



[caption id="attachment_12" align="aligncenter" width="656" caption="OUTPUT"]Program to calculate area of a circle[/caption]



Sunday, January 2, 2011

Program to find out sum of any two integers.

/*
Name:  Program to find out sum of any two integers.
Author: Parveen Malik
Date: 02/01/11 16:05
*/

#include<stdio.h>
#include<conio.h>   // preprocessor section


void main()
{
int n1,n2,sum; //declare integers

printf("Enter any two integers \n");
scanf("%d%d",&n1,&n2); // for the user input

sum=n1+n2;

printf("\n\n%d + %d = %d",n1,n2,sum); // to print the sum


getch();
}
 

[caption id="attachment_11" align="aligncenter" width="655" caption="OUTPUT"]Program to find out sum of any two integers.[/caption]