Your Ad Here

Thursday, January 17, 2008

Logical Operation On Numbers - C Program

/* C Program For Implementation Of Logical Operations on Two Numbers, The Logical Operations Include Logical AND, Logical OR and Logical NOT */


#include<>
#include<>
#include<>

void result(int,int,int);
void main()
{
int n1,n2,ch,c; clrscr();
do
{
printf("Enter Two Numbers : \n");
scanf("%d%d",&n1,&n2);
printf("************* MENU FOR LOGICAL OPERATIONS ***********\n");
printf("1. AND\n2. OR\n3. NOT\n\nEnter Your Choice ");
scanf("%d",&ch);
result(n1,n2,ch);
printf("\nDo you want to continue?\n1. Yes\n2. No\n");
scanf("%d",&c);
}
while(c == 1);
getch();
}
void result(int a,int b,int c)
{
int b1[8], b2[8], res[8], c1[8], c2[8];
int i,n,s,s1,s2,x,y;
x = a;
y = b;
if(c!=1 && c!=2 && c!=3)
{
clrscr();
printf("ERROR!!!!!!!!! INVALID ENTRY!!\n");
main();
}
/* Conversion to binary */
if(x< x =" x+256;" y =" y+256;" i="0;i<" x="="0)" x="x/2;" i="0;i<" y="="0)" y="y/2;" c="="1)" n="0;" c="="2)" n="1;" i="0;i<" c="="3)" i="0;i<" c="="1" c="="2)" s="0;" i="0;i<" s =" s" c="="3)" s1="0;" i="0;i<" s1 =" s1" s2="0;" i="0;i<" s2 =" s2" i="7;i">=0;i--)
printf("%d",b1[i]);
printf("\t\t%d",a);
printf("\t\n\t Second\t\t\t");
for(i=7;i>=0;i--)
printf("%d",b2[i]);
printf("\t\t%d",b);
printf("\t\n\t Result\t\t\t");
if(c==1 c==2)
{
for(i=7;i>=0;i--)
printf("%d",res[i]);
printf("\t\t%d",s);
}
if(c==3)
{
for(i=7;i>=0;i--)
printf("%d",c1[i]);
printf("\t\t%d",s1);
printf("\t\n\tResult 2\t\t\t");
for(i=7;i>=0;i--)
printf("%d",c2[i]);
printf("\t\t%d",s2);
}
printf("\t\n\t--------------------------------");
printf("---------------------------------\n");
}


/******************* OUTPUT *****************
Enter Two Numbers :
5
2
************* MENU FOR LOGICAL OPERATIONS ***********
1. AND
2. OR
3. NOT
Enter Your Choice 1
___________________________________________
Number Binary Decimal
-----------------------------------------------------------------
First 00000101 5
Second 00000010 2
Result 00000000 0
-----------------------------------------------------------------
Do you want to continue?
1. Yes
2. No
1
Enter Two Numbers :
6
3
************* MENU FOR LOGICAL OPERATIONS ***********
1. AND
2. OR
3. NOT
Enter Your Choice 2
_________________________________________________________________
Number Binary Decimal
-----------------------------------------------------------------
First 00000110 6
Second 00000011 3
Result 00000111 7
-----------------------------------------------------------------
Do you want to continue?
1. Yes
2. No
1
Enter Two Numbers :
8
5
************* MENU FOR LOGICAL OPERATIONS ***********
1. AND
2. OR
3. NOT
Enter Your Choice 3
_________________________________________________________________
Number Binary Decimal
-----------------------------------------------------------------
First 00001000 8
Second 00000101 5
Result 11110111 247
Result 2 11111010 250
-----------------------------------------------------------------
Do you want to continue?
1. Yes
2. No 2 */

1 comment:

Zulkaif said...

I fully agree with you

Your Ad Here