fork download
  1. #include <stdio.h>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int main(){
  5. cout<<"Logical Address:";
  6. string s;
  7. cin>>s;
  8. int m=s.length();
  9. int n,d;
  10. cout<<"Enter n,d:";
  11. cin>>n>>d;
  12. int md=m-d;
  13. int k=pow(2,md);
  14. int num=0;
  15. for(int i=0;i<md;i++){
  16. num+=(s[i]-'0')*pow(2,md-i-1);
  17. }
  18. s=s.substr(md);
  19. int nd=n-d;
  20. int l=pow(2,nd);
  21. int arr[k];
  22. for(int i=0;i<k;i++){
  23. arr[i]=(l/k)*i;
  24. }
  25. cout<<"page no\tframe no:\n";
  26. for(int i=0;i<k;i++){
  27. cout<<i<<"\t"<<arr[i]<<"\n";
  28. }
  29. string st="";
  30. num=arr[num];
  31. while(num!=0){
  32. string z="";
  33. z+=(num%2+'0');
  34. st=z+st;
  35. num/=2;
  36. }
  37. if(st.length()==nd){
  38. s=st+s;
  39. }
  40. else {
  41. for(int i=st.length();i<nd;i++){
  42. st="0"+st;
  43. }
  44. s=st+s;
  45. }
  46. cout<<s<<endl;
  47. }
Success #stdin #stdout #stderr 0.01s 7816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:2: expected object
./prog:31: expected expression