Showing posts with label Basic I/O. Show all posts
Showing posts with label Basic I/O. Show all posts

Friday, March 2, 2012

Roots of a Quadratic Equation

/* A program to find roots of a quadratic equation*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int a,b,c;
float d,r1,r2,x,y;
clrscr();

printf("Enter the values of a,b,c:");
scanf("%d%d%d",&a,&b,&c);

d=b*b-4*a*c;
r1=(-b+sqrt(abs(d)))/(2*a);
r2=(-b-sqrt(abs(d)))/(2*a);
x=-b/(2*a);
y=sqrt(abs(d))/(2*a);

if(d=0)
   printf("The roots are real and equal which is %f.",x);

else if(d>0)
   printf("The roots are real and unequal which are %f and %f.",r1,r2);

else
   printf("The roots are imaginary and unequal which are %f+i%f and %f-iy",x,y,x,y);

getch();
}

Armstrong Number

/* A program to check whether a number is armstrong or not*/
// An armstrong number is such that sum of cube of its digit is same number
// e.g. 153 = 1^3 +5^3 +3^3

     #include<stdio.h>
     #include<conio.h>
     #include<math.h>
      main()
      {
     int a,b,c,d,x;
     printf("enter a 3 digit number:" );
     scanf("%d",&x);
     a=x%10;
     b=(x/10)%10;
     c=(x/100)%10;
     d=pow(a,3)+pow(b,3)+pow(c,3);
     if (d==x)
     {printf("armstrong");
     }
     else{printf("not armstrong");}
     getch();
     }