ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى


انضم إلى المنتدى ، فالأمر سريع وسهل

ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى
ملتقى البرمجة
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

التحويل بين نظامي العد الثنائي والعشري

اذهب الى الأسفل

التحويل بين نظامي العد الثنائي والعشري Empty التحويل بين نظامي العد الثنائي والعشري

مُساهمة من طرف Basel Tamimi 4/4/2011, 1:27 pm

اكتب برنامج للتحويل بين نظامي العد الثنائي والعشري بناء على مدخلات المستخدم


الحل:

الكود:
#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;}


اول مرة بحل سؤال واضح هيك ^__^
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى