Pages

Saturday 15 September 2012

QUADRATIC EQUATION

/* Quadratic Equation*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float r1,r2,s;
printf("enter a,b,c");
scanf("%d%d%d",&a,&b,&c);
d=b*b-(4*a*c);
s=sqrt(d);
if(d>=0)
{
r1=(-b+s)/(2*a);
r2=(-b-s)/(2*a);
if(r1==r2)
{
printf("the roots are real and equal\n");
printf("the root is %5.3f\n",r1);
}
else
printf("the roots are real and distinct\n");
printf("the roots are %5.3f and %5.3f\n",r1,r2);
}
else
printf("imaginary roots\n");
}

SUM AND REVERSE OF A NUMBER

/*Sum And Reverse Of A Number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,rev=0,r;
printf("enter the number");
scanf("%d",&n);
while(n>0)
{
r=n%10;
rev=(rev*10)+r;
sum=sum+r;
n=n/10;
}
printf("sum is %d",sum);
printf("\n reverse is %d",rev);
getch();
}


FACTORIAL OF A NUMBER


/*Factorial Of A Number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact=1,i=1;
printf("enter number");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("factorial is %d",fact);
getch();
}

ARITHMETIC OPERATIONS

/*Arithmetic Operations*/ 

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int ch;
printf("enter the numbers");
scanf("%d%d",&a,&b);
printf("enter your choice");
Printf("1.multiplication,2.division,3.addition,4.subtraction");
scanf("%d",&ch);
if(ch>0)
{
if(ch==1)
{
printf("product=%d",a*b);
}
else
if(ch==2)
{
printf("quotient=%d",a/b);
}
else
if(ch==3)
{
printf("sum=%d",a+b);
}
else
if(ch==4)
{
printf("diff=%d",a-b);
}
else
printf("Invalid choice");
getch();
}
}



AMICABLE NUMBERS



/*Amicable Numbers*/


#include<stdio.h>
#include<conio.h>
void main()
{
int i,r=0,sum=0,sum1=0,a,b,temp,temp1;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);
temp=a;
for(i=1;i<=a/2;i++)
{
r=a%i;
if(r==0)
sum+=i;
}
temp=b;
for(i=1;i<=b/2;i++)
{
r=b%i;
if(r==0
sum1+=i;
}
if((sum==temp1)&&(sum==temp))
printf("amicable");
else
printf("not amicable");
getch();
}