Follow along with the video below to see how to install our site as a web app on your home screen.
Забелешка: This feature may not be available in some browsers.
#include< stdio.h>
#include< conio.h>
#include< math.h>
int exor(int n1, int n2)
{
if(n1==n2)
return 0;
else
return 1;
}
int min(int n1, int n2)
{
if(n1< n2)
return n1;
else
return n2;
}
int max(int n1, int n2)
{
if(n1>=n2)
return n1;
else
return n2;
}
void main()
{
int a1[10],a2[10],a3[10],a4[10],a5[10],a7[10],a8[10],a11[10];
int j=0,i=0,p=0,n1=0,n3=0,n4=0,n5=0,n6=0,n7=0,n8=0;
int a,b,c,h,v,o, n,q,r,x,y,S,Z,c1,c2,c3,c4,s1,carry;
int g[8],p1[10],p2,p3[10],p4[10],s[8],w[8],z[8];
clrscr();
do
{ printf("\t\tCALCULATIONS OF BINARY ARITHMETIC OPERATIONS\n");
printf("\t --------------------------------------------\n");
printf("1: BINARY ADDITION \n");
printf("2: BINARY SUBTRACTION\n");
L:
printf("\nENTER THE OPERATION YOU WOULD LIKE TO CARRY OUT:");
scanf("%d",&n);
switch(n)
{case 1:
{M:
printf("\nEnter The First Number :");
scanf("%d",&x);
if(x>0)
printf("x = %d\n",x);
else
{ printf("The Entered Number Is Invalid\n");
printf("Please Enter the valid value\n");
goto M;
}
for(i=0;i< =7;i++)
{ z[i]=0; s[i]=0; }
i=7;
do
{ z[i]=x%2;
x=x/2;
i--;
}while(x!=0);
printf("The binary equivalent of x is: ");
for(j=0;j< =7;j++)
{ printf("%d",z[j]); }
N:
printf("\n\nEnter the second number : ");
scanf("%d",&y);
if(y>=0)
printf("y = %d\n",y);
else
{ printf("The entered number is invalid\n");
printf("Please enter the valid value\n");
goto N;
}
i=7;
do
{ s[i]=y%2;
y=y/2;
i--;
}while(y!=0);
printf("The binary equivalent of y is: ");
for(p=0;p< =7;p++)
{ printf("%d",s[p]); }
printf("\n\nBinary of x: ");
for(i=0;i< =7;i++)
{printf("%d",z[i]); }
printf("\nBinary of y: ");
for(i=0;i< =7;i++)
{printf("%d",s[i]); }
for(h=7;h>=0;h--)
{s1=exor(carry,exor(z[h],s[h]));
c1=min(z[h],s[h]);
c2=min(s[h],carry);
c3=min(z[h],carry);
c4=max(c3,max(c1,c2));
carry=c4;
a1[h]=s1; }
printf("\nSum : ");
for(b=0;b< =7;b++)
{ printf("%d",a1[b]); }
for(v=0;v< =7;v++)
{ o=pow(2,7-v);
n1=n1+(a1[v]*o); }
printf("\n\nDecimal Equivalent of Sum : ");
printf("%d",n1);
break;
}
case 2:
{ printf("\nEnter the first number : ");
scanf("%d",&x); Z=x;
printf("x = %d",x);
for(i=0;i< =7;i++)
{ z[i]=0; s[i]=0; }
if(Z>0)
{i=7;
do
{ z[i]=x%2;
x=x/2;
i--;
}while(x!=0);
printf("\nThe binary equivalent of x is: ");
for(j=0;j< =7;j++)
{ printf("%d",z[j]); }
}
if(Z< 0)
{i=7;
do
{ z[i]=x%2;
x=x/2;
if(z[i]< 0)
z[i]=-z[i];
i--;
}while(x!=0);
printf("\nThe binary equivalent of x is: ");
for(j=0;j< =7;j++)
{ printf("%d",z[j]); }
for(h=0;h< =7;h++)
{ w[h]=z[h];p3[h]=1-w[h]; }
printf("\n\nThe 1'S Complement of x is: ");
for(b=0;b< =7;b++)
{ printf("%d",p3[b]); }
if(p3[7]==1)
{ p3[7]=0;carry=1;}
else
if(p3[7]==0)
{p3[7]=1;carry=0;}
for(h=6;h>=0;h--)
{ s1=exor(carry,p3[h]);
c1=min(p3[h],carry);
carry=c1;
p3[h]=s1;
}
printf("\nThe 2'S Complement of x is: ");
for(b=0;b< =7;b++)
{ printf("%d",p3[b]); }
}
printf("\n\nEnter the second number : ");
scanf("%d",&y);S=y;
printf("y = %d",y);
if(S< 0)
{p=7;
do
{ s[p]=y%2;
y=y/2;
if(s[p]< 0)
s[p]=-s[p];
p--;
}while(y!=0);
printf("\nThe binary equivalent of y is: ");
for(q=0;q< =7;q++)
{ printf("%d",s[q]); }
printf("\n________________________________________________");
}
if(S>0)
{p=7;
do
{ s[p]=y%2;
y=y/2;
p--;
}while(y!=0);
printf("\nThe binary equivalent of y is: ");
for(q=0;q< =7;q++)
{ printf("%d",s[q]); }
for(h=0;h< =7;h++)
{ w[h]=s[h];
p4[h]=1-w[h];
}
printf("\nThe 1'S Complement of y is: ");
for(b=0;b< =7;b++)
{ printf("%d",p4[b]); }
if(p4[7]==1)
{ p4[7]=0;carry=0;}
else
if(p4[7]==0)
{ p4[7]=1;carry=0; }
for(h=6;h>=0;h--)
{ s1=exor(carry,p4[h]);
c1=min(p4[h],carry);
carry=c1;
p4[h]=s1; }
printf("\nThe 2'S Complement of y is: ");
for(b=0;b< =7;b++)
{ printf("%d",p4[b]); }
printf("\n_______________________________________________");
}
if(Z< 0 && S< 0)
{ printf("\n2'S Complement of x: ");
for(h=0;h< =7;h++)
{ printf("%d",p3[h]); }
printf("\nBinary of y : ");
for(h=0;h< =7;h++)
{ printf("%d",s[h]); }
for(h=7;h>=0;h--)
{ s1=exor(carry,exor(p3[h],s[h]));
c1=min(p3[h],s[h]);
c2=min(s[h],carry);
c3=min(p3[h],carry);
c4=max(c3,max(c1,c2));
carry=c4;
a2[h]=s1;
}
if(carry==0)
{ printf("\nDifference : ");
for(y=0;y< =7;y++)
{ printf("%d",a2[y]);
a2[y]=1-a2[y]; }
printf("\nAnswer is Negative and is in 2'S Complement form");
printf("\n1'S Complement : ");
for(y=0;y< =7;y++)
{ printf("%d",a2[y]); }
if(a2[7]==1)
{ a2[7]=0; carry=1;}
else
{ a2[7]=1; carry=0; }
for(i=6;i>=0;i--)
{ c1=exor(carry,a2[i]);
c2=min(a2[i],carry);
carry=c2;
a2[i]=c1;
}
printf("\n2'S Complement : ");
for(y=0;y< =7;y++)
{
printf("%d",a2[y]);
n3=n3+(a2[y] *pow(2,7-y));
}
printf("\nDecimal Equivalent of Difference : ");
printf("%d",n3);
}
else
{
if(carry==1)
{
printf("\nDifference : ");
for(y=0;y< =7;y++)
{
printf("%d",a2[y]);
}
for(y=0;y< =7;y++)
{
n4=n4+(a2[y] *pow(2,7-y));
}
printf("\nDecimal Equivalent of Difference : ");
printf("%d",n4);
}
}
}
if(Z>0 && S>0)
{
printf("\nBinary of x : ");
for(h=0;h< =7;h++)
{
printf("%d",z[h]);
}
printf("\n2'S Complement of y : ");
for(h=0;h< =7;h++)
{
printf("%d",p4[h]);
}
for(h=7;h>=0;h--)
{
s1=exor(carry,exor(z[h],p4[h]));
c1=min(z[h],p4[h]);
c2=min(p4[h],carry);
c3=min(z[h],carry);
c4=max(c3,max(c1,c2));
carry=c4;
a5[h]=s1;
}
if(carry==1)
{
printf("\nDifference : ");
for(y=0;y< =7;y++)
{
printf("%d",a5[y]);
}
for(y=0;y< =7;y++)
{
n5=n5+(a5[y] *pow(2,7-y));
}
printf("\nDecimal Equivalent of difference : ");
printf("%d",n5);
}
else
if(carry==0)
{
printf("\nDifference : ");
for(y=0;y< =7;y++)
{
printf("%d",a5[y]);
a5[y]=1-a5[y];
}
printf("\nAnswer is Negative and is in 2'S Complement form");
printf("\n1'S Complement is : ");
for(y=0;y< =7;y++)
printf("%d",a5[y]);
if(a5[7]==1)
{
a5[7]=0; carry=1;
}
else
{
a5[7]=1; carry=0;
}
for(i=6;i>=0;i--)
{
c1=exor(carry,a5[i]);
c2=min(a5[i],carry);
carry=c2;
a5[i]=c1;
}
printf("\n2'S Complement is : ");
for(y=0;y< =7;y++)
{
printf("%d",a5[y]);
n6=n6+(a5[y] *pow(2,7-y));
}
printf("\nDecimal Equivalent of difference : ");
printf("%d",n6);
}
}
if(Z< 0 && S>0)
{
printf("\n2'S Complement of x : ");
for(h=0;h< =7;h++)
{
printf("%d",p3[h]);
}
printf("\n2'S Complement of y : ");
for(h=0;h< =7;h++)
{
printf("%d",p4[h]);
}
for(h=7;h>=0;h--)
{
s1=exor(carry,exor(p3[h],p4[h]));
c1=min(p3[h],p4[h]);
c2=min(p4[h],carry);
c3=min(p3[h],carry);
c4=max(c3,max(c1,c2));
carry=c4;
a8[h]=s1;
}
printf("\nDifference : ");
for(y=0;y< =7;y++)
{
printf("%d",a8[y]);
a8[y]=1-a8[y];
}
printf("\nAnswer is Negative and is in 2'S Complement form");
printf("\n1'S Complement is : ");
for(y=0;y< =7;y++)
printf("%d",a8[y]);
if(a8[7]==1)
{
a8[7]=0; carry=1;
}
else
{
a8[7]=1; carry=0;
}
for(i=6;i>=0;i--)
{
c1=exor(carry,a8[i]);
c2=min(a8[i],carry);
carry=c2;
a8[i]=c1;
}
printf("\n2'S Complement is : ");
for(y=0;y< =7;y++)
{
printf("%d",a8[y]);
n7=n7+(a8[y] *pow(2,7-y));
}
printf("\nDecimal Equivalent of difference : ");
printf("%d",n7);
}
if(Z>0 && S< 0)
{
printf("\nBinary of x : ");
for(h=0;h< =7;h++)
{ printf("%d",z[h]); }
printf("\nBinary of y : ");
for(h=0;h< =7;h++)
{ printf("%d",s[h]); }
for(h=7;h>=0;h--)
{
s1=exor(carry,exor(z[h],s[h]));
c1=min(z[h],s[h]);
c2=min(s[h],carry);
c3=min(z[h],carry);
c4=max(c3,max(c1,c2));
carry=c4;
a11[h]=s1;
}
printf("\nDifference : ");
for(y=0;y< =7;y++)
{ printf("%d",a11[y]); }
for(y=0;y< =7;y++)
{ n8=n8+(a11[y] *pow(2,7-y)); }
printf("\nDecimal Equivalent of difference : ");
printf("%d",n8);
}
break;
default:
clrscr();
printf("ERROR!!!!!!!\nINVALID ENTRY\n");
}
}
printf("\n-------------------------------------------------");
printf("\nWould You Like To Continue\n");
printf("Please Enter '1' For 'YES' And '0' For 'NO': ");
scanf("%d",&r);
if(r==0)
{ printf("\n************** THANK YOU ***************\n") }
}while(r==1);
getch();
}
/******************** OUTPUT **********************
CALCULATIONS OF BINARY ARITHMETIC OPERATIONS
--------------------------------------------
1: BINARY ADDITION
2: BINARY SUBTRACTION
ENTER THE OPERATION YOU WOULD LIKE TO CARRY OUT:1
Enter The First Number :5
x = 5
The binary equivalent of x is: 00000101
Enter the second number : 2
y = 2
The binary equivalent of y is: 00000010
Binary of x: 00000101
Binary of y: 00000010
Sum : 00001001
Decimal Equivalent of Sum : 9
-------------------------------------------------
Would You Like To Continue
Please Enter '1' For 'YES' And '0' For 'NO': 1
CALCULATIONS OF BINARY ARITHMETIC OPERATIONS
--------------------------------------------
1: BINARY ADDITION
2: BINARY SUBTRACTION
ENTER THE OPERATION YOU WOULD LIKE TO CARRY OUT: 2
Enter the first number : 4
x = 4
The binary equivalent of x is: 00000100
Enter the second number : 3
y = 3
The binary equivalent of y is: 00000011
The 1'S Complement of y is: 11111100
The 2'S Complement of y is: 11111101
_______________________________________________
Binary of x : 00000100
2'S Complement of y : 11111101
Difference : 00000001
Decimal Equivalent of difference : 1
-------------------------------------------------
Would You Like To Continue
Please Enter '1' For 'YES' And '0' For 'NO': 1
CALCULATIONS OF BINARY ARITHMETIC OPERATIONS
--------------------------------------------
1: BINARY ADDITION
2: BINARY SUBTRACTION
ENTER THE OPERATION YOU WOULD LIKE TO CARRY OUT:2
Enter the first number : 4
x = 4
The binary equivalent of x is: 00000100
Enter the second number : 9
y = 9
The binary equivalent of y is: 00001001
The 1'S Complement of y is: 11110110
The 2'S Complement of y is: 11110111
_______________________________________________
Binary of x : 00000100
2'S Complement of y : 11110111
Difference : 11111011
Answer is Negative and is in 2'S Complement form
1'S Complement is : 00000100
2'S Complement is : 00000101
Decimal Equivalent of difference : 5
-------------------------------------------------
Would You Like To Continue
Please Enter '1' For 'YES' And '0' For 'NO': 1
CALCULATIONS OF BINARY ARITHMETIC OPERATIONS
--------------------------------------------
1: BINARY ADDITION
2: BINARY SUBTRACTION
ENTER THE OPERATION YOU WOULD LIKE TO CARRY OUT:2
Enter the first number : 6
x = -6
The binary equivalent of x is: 00000110
The 1'S Complement of x is: 11111001
The 2'S Complement of x is: 11111010
Enter the second number : 5
y = 5
The binary equivalent of y is: 00000101
The 1'S Complement of y is: 11111010
The 2'S Complement of y is: 11111011
_______________________________________________
2'S Complement of x : 11111010
2'S Complement of y : 11111011
Difference : 11110101
Answer is Negative and is in 2'S Complement form
1'S Complement is : 00001010
2'S Complement is : 00001011
Decimal Equivalent of difference : 11
-------------------------------------------------
Еден совет.. Ако ти е програмава колку да завршиш работа, а несакаш да учиш програмирање, ок. Ама ако сакаш да научиш, седни и мисли ја, оваква задача треба да ја мозгаш малку. Првин ќе видиш како го пресметуваш тоа во реален живот, па после ќе се обидеш да ја решаваш..Ми треба програма за одземање на бинарни броеви во C или C++ , заглавив ептен деновиве со тоа па ако има некој нешто слично го молам да ми прати.. Благодарам !!
Зошто не ги направиш во декадни, па потоа повторно во бинарни? Според мене така е полесно.Ми треба алгоритам во Ц или Ц++ за одземање на бинарни броеви, па ако има некој нешто слично ве молам да ми го пратите, ептен заглавив со тоа.. Фала!
Напиши на Google: Teach yourself C++ in 21 days. Книгава е најдобра според мене.Барам совет од поискусните:прва година сум средно и во школо во ц++ стигнавме до вмрежени for,do while,while наредби претходно ги изучивме обичните,учевме if else,и switch и некои операции во math.h,за оваа година толку ни кажаа до крајот ке учиме некои глупости во ексел сега барам совет кои наредби/синтакси да продолжам да ги учам и која книга би била најдобра за тоа,инаку гореспоменатите ги владејам прилично добро.
Зошто не ги направиш во декадни, па потоа повторно во бинарни? Според мене така е полесно.
--- надополнето: 22 април 2012 во 01:58 ---
Напиши на Google: Teach yourself C++ in 21 days. Книгава е најдобра според мене.![]()
{
int a, b, c ;
float P, L, V;
char odg;
cout <<"Vnesi gi stranite a, b, c na kvadarot"<<endl;
cout<<"a= "<<endl;
cin>>a;
cout<<"b= "<<endl;
cin>>b;
cout<<"c= "<<endl;
cin>>c;
L=2*(a+b);
P=a*b;
V=a*b*c;
cout<<"Sto sakas da bide presmetano"<<endl;
cout<<"1. Perimetar na osnovata"<<endl;
cout<<"2. Plostina na osnovata"<<endl;
cout<<"3. Volumen na kvadarot"<<endl;
cout<<"0. Otkazi"<<endl;
cin>> odg ;
while odg!=0
{
if(odg==1) нека пресмета периметар
else if(odg==2) нека пресмета плоштина
итн...
else cout << "Pogresen vnes"
}
Код:while odg!=0 { if(odg==1) нека пресмета периметар else if(odg==2) нека пресмета плоштина итн... else cout << "Pogresen vnes" }
cin >> odg стај го да биде пред while циклусот
Код:while odg!=0 { if(odg==1) нека пресмета периметар else if(odg==2) нека пресмета плоштина итн... else cout << "Pogresen vnes" }
cin >> odg стај го да биде пред while циклусот
Пошто тогаш бев у брзање и за помалце од минута го напишав тој код без компајлер, без ништо, туку директно во постот, еве сеа ќе се исправам.Е вака ми ги повторува како do/loop во VBS. Чаре ?
#include <iostream>
using namespace std;
int main()
{
float a, b, c;
float P, L, V;
char odg;
cout << "Vnesi gi stranite a, b, c na kvadarot" << endl;
cout << "a= ";
cin >> a;
cout << "b= ";
cin >> b;
cout << "c= ";
cin >> c;
L=2*(a+b);
P=a*b;
V=a*b*c;
do {
cout << endl << endl;
cout << "Sto sakas da bide presmetano" << endl;
cout << "1. Perimetar na osnovata" << endl;
cout << "2. Plostina na osnovata" << endl;
cout << "3. Volumen na kvadarot" << endl;
cout << "0. Otkazi" << endl;
cin >> odg ;
if (odg=='1') cout << "Perimetarot e " << L << endl;
else if (odg=='2') cout << "Plostinata e " << P << endl;
else if (odg=='3') cout << "Volumenot e " << V << endl;
else if (odg=='0') cout << "Programata zavrsi" << endl;
else cout << "Pogresen vnes, probajte povtorno" << endl;
} while (odg!='0');
system ("pause");
return 0;
}
Пошто тогаш бев у брзање и за помалце од минута го напишав тој код без компајлер, без ништо, туку директно во постот, еве сеа ќе се исправам.
3.dali zbirot na cifrite na nekoj broj e deliv so 5;
{
int n,i,n1,s,
cin>>n;
s=0;
for (i=1; i<=n;i++)
{
n1=n%10;
s+=n1;
n=n/10;
}
if (S%5==0) cout<<se deli;
else cout <<ne se deli;
return 0;
}