التحويل بين نظامي العد الثنائي والعشري
صفحة 1 من اصل 1
التحويل بين نظامي العد الثنائي والعشري
اكتب برنامج للتحويل بين نظامي العد الثنائي والعشري بناء على مدخلات المستخدم
الحل:
- الكود:
#include <iostream>
#define z 10
#define w 18
using namespace std;
int main (){
int x;
//x = your choises
cout<<"\t\t Welcome To This Program:\n"
<<"\t\t ------------------------\n"
<<"This program is for converting between binary and decimal \n"
<<"so choose from the operator below:\n"
<<"1) Binary > Decimal\n"
<<"2) Decimal > Binary\n"
<<"3) About the program\n"
<<"4) Exit\n"
<<endl
<<"Your choise is: ";
cin>>x;
while(x==1 || x==2 || x==3){
switch(x){
case 1: {
/*
keys:
-----
k = the array counter
power = 2^....
bnum = the binary number
dnum = the decimal number before adding to the array
binary[] = the binary array which need process
decimal[] = the decimal array or processed binary array
z = array size
result = the final decimal num after all processing
*/
int k,power,bnum,dnum,binary[z],decimal[z],result;
cout<<endl
<<"Enter 10 digit binary number: ";
cin>>bnum;
for(k=0;k<9;k++){
dnum=(bnum%10);
binary[k]=dnum;
bnum=bnum/10;}
binary[9]=bnum;
decimal[0]=binary[0];
power=1;
for(k=1;k<=9;k++){
power=power*2;
decimal[k]=binary[k]*power;
}
result=0;
for(k=0;k<z;k++)
result=result+decimal[k];
cout<<"The decimal number is= "<<result<<endl;
;break;}
case 2: {
/*
keys:
-----
b[] = the array name
w = max size of the array
a = the entered number
i = the number which processed
k = the counter which for entering num to the array
j = the counter which for printing num from the array
*/
int a,i,k,j,b[w];
cout<<endl
<<"Enter 5 digits integer number: ";
cin>>a;
k=0;
for (i=a;i>=1;i=i/2){
b[k]=i%2;
k++;
}
cout<<"The bin number is= ";
for (j=(k-1);j>=0;j--)
cout<<b[j];
cout<<endl;break;
}
case 3: { cout<<endl
<<"About The Program:\n"
<<"-----------------\n"
<<"This is just a simple program which convert between\n"
<<" 1) 10 digit binary number to its dicemal\n"
<<" 2) 5 digit dicemal number to its binary\n"
<<"Just enter the number in correct way to get correct result.\n"
<<"Hope to improve the program soon\n"
<<"Thanks for use\n"
<<endl
<<"Basel Y. Tamimi\n";
}
default:break;}
cout<<"______________________________________________________________\n";
cout<<endl;
cout<<"\t\t Choose other operator:\n"
<<"\t\t ----------------------\n"
<<endl
<<"Your new operator is: ";
cin>>x;
}
return 0;}
اول مرة بحل سؤال واضح هيك ^__^
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
3/7/2011, 11:05 pm من طرف anas mohtaseb
» امتحان الفاينال لمختبر برمجة الحاسوب
26/5/2011, 1:45 pm من طرف Basel Tamimi
» حل سؤال الموظفين والرواتب
22/5/2011, 3:17 pm من طرف Basel Tamimi
» sum program with parameters
22/5/2011, 9:33 am من طرف Basel Tamimi
» مختبر 9
18/5/2011, 5:43 pm من طرف Basel Tamimi
» سلايدات الكتاب للاقسام 4 5 7
6/5/2011, 2:07 pm من طرف Basel Tamimi
» شكرا لكم
4/5/2011, 8:51 pm من طرف anas mohtaseb
» Programming Assignment الحل الثاني
2/5/2011, 7:58 am من طرف Basel Tamimi
» سؤال على ال parallel arrays
1/5/2011, 5:06 am من طرف Basel Tamimi