Sunday, May 26, 2013

Complex number

#include<iostream.h>
#include<conio.h>
class complex
{
                float real;
                float imag;
   public:
                void getnum();
                void putnum();
                void sum(complex,complex);
                void dif(complex,complex);
};
void complex::getnum()
{
                cout<<"\nEnter the real part : ";
                cin>>real;
                cout<<"\nEnter the imaginary part : ";
                cin>>imag;
}
void complex::putnum()
{
                cout<<real;
                if(imag<0)
                                cout<<imag<<"i\n";
                else
                                cout<<"+"<<imag<<"i\n";
}
void complex::sum(complex a,complex b)
{
                real=a.real+b.real;
                imag=a.imag+b.imag;
}
void complex::dif(complex a,complex b)
{
                real=a.real-b.real;
                imag=a.imag-b.imag;
}
int main()
{
                complex c1,c2,c3,c4;
                cout<<"\nEnter first complex number\n";
                c1.getnum();
                cout<<"\nEnter second complex number\n";
                c2.getnum();
                //Sum of two inputted numbers
                c3.sum(c1,c2);
                cout<<"\nThe Sum is : ";
                c3.putnum();
                //Difference of two inputted numbers
                c4.dif(c1,c2);
                cout<<"\nThe Difference is : ";
                c4.putnum();


Output:
Enter first complex number
Enter the real part : 4
Enter the imaginary part : 5
Enter second complex number
Enter the real part : 3
Enter the imaginary part : 6
The Sum is : 7+11i
The Difference is : 1-1i

Friday, February 1, 2013

Find Prime Factor of number


/*Program to find out prime factors of a given number.*/

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

void main()
{
int number;
printf("Enter a number ");
scanf("%d",&number);
printf("\nThe prime factors of %d are:",number);
for(int num=2;num<32767;num++)
{
int i=2;
while(i<=num-1)
{
if(num%i==0)
{
break;
}
i++;
}
if(i==num)
{
if(number%num==0)
{
number=number/num;
printf("\t%d",num);
num=1;
}
else
{
continue;
}
}
}
getch();
clrscr();
}

Find Generic root of number


#include <stdio.h>
int main()
{        

int num,i;
printf("Enter any number: ");
scanf("%d",&num);
printf("Generic root: %d", (i = num % 9) ? i : 9);
return 0;
}

Add Two numbers without using operator


#include<stdio.h>

int main(){
  
    int a,b;
    int sum;

    printf("Enter any two integers: ");
    scanf("%d%d",&a,&b);

    //sum = a - (-b);
    sum = a - ~b -1;

    printf("Sum of two integers: %d",sum);

    return 0;
}


Tuesday, June 26, 2012

Print 1 to 10 Series


#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("the no from 1 to 10 are:\n");
for(a=1;a<=10;a++)
printf("%d\n", a);
getch();
}

Tuesday, January 17, 2012

Convert Decimal to Hexadecimal Number


#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
Int x, y=30, z;
clrscr();
printf(“Enter the number:);
scanf(%d”, &x);
printf(“\n conversion of decimal to hexadecimal number\n”);
for(;;)
{
if(x= =0)
exit(1);
z=x%16;
x=x/16;
gotoxy(y--,5);
switch(z)
{
Case 10:
Printf(“A”);
Break;
Case 11:
Printf(%c”, „B?);
Break;
Case 12:
Printf(%c”, „C”);
Break;
Case 13:
Printf(“D”);
Break;
Case 14:
Printf(“E”);
Break;
Case 15:
Printf(“F”);
Default:
Printf(%d”, z);
}
}
getch();
}

Output:
Enter the number: 31
Conversion of decimal to Hexa decimal number
1F