Friday, January 02, 2009

Progeam to convert Decimal number to Binary

Buzz It
/*Progeam to convert Decimal number to Binary*/

//

#include
#include
void main()
{
int b[50],i;
int n;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
for(i=0;n>0;i++)
{
b[i]=n%2;
n=n/2;
}
printf("The binary number is=\t");
for(i=i-1;i>=0;--i)
{
printf("%d",b[i]);
}
getch();
}


-->

Program to convert binary number to Decimal number

Buzz It
/*Program to convert binary number to Decimal number */

//

#include
#include
#include
void main()
{
int dec=0,i=0,d;
long bin;
clrscr();
printf("Enter the number \n");
scanf("%ld",&bin);
for(i=0;bin>0;i++)
{
d=bin%10;
dec=dec+(d*pow(2,i));
bin=bin/10;
}
printf("The decimal =\t%d",dec);
getch();
}

-->

Program to find prime number

Buzz It
/*Program to find prime number*/

//
#include
#include
void main()
{
int n,i,p;
clrscr();
printf("Enter the number \n");
scanf("%d",&n);
if(n==2)
printf("The number is a prime");
else
{
for(i=2;i {
p=n%i;
if(p==0)
{
printf("The number is prine");
break;
}
}
if(p!=0)
printf("number is not prime");
}
getch();
}

-->

Program to genarate fibanocci serous

Buzz It
/*Program to genarate fibanocci serous*/
//
#include
#include
void main()
{
int a,b,c,n,i;
clrscr();
printf("Enter the number \n");
scanf("%d",&n);
a=-1;
b=1;
printf("The Fiboacci serous is=\t");
for (i=0;i {
c=a+b;
printf("%d\t",c);
a=b;
b=c;
}
getch();
}

-->

Program to find the factorial of anumber

Buzz It
/*Program to find the factorial of anumber*/

#include
#include
void main()
{
int n,r;
clrscr();
printf("Enter anumber ");
scanf("%d",&n);
r=fact(n);
printf("The Factorial is=\t%d" ,r);
getch();
}
fact(int x)
{
int f;
if (x==1)
return (1);
else
f=x*fact(x-1) ;
return(f);
}

Program to find biggest of 3 numbers

Buzz It
/*Program to find biggest of 3 numbers*/


#include
#include
void main()
{
int a,b,c;
clrscr();
printf("Enter three number \n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("the large is =%d",a);
else
printf("The large is =%d",c);
}
else
{
if(b>c)
printf("large is=%d",b);
else
printf("large is =%d",c);
}
getch();
}