quantum

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include<iostream>
using namespace std;
void truth_table(int n);
int main()
{
cout<<"n:(>=0): ";
int n;
cin>>n;
while (n <= 0){ /*error loop */
cout<<"n:(>=0): ";
cin>>n;
}
truth_table(n);
return 0;
}

void truth_table(int n)
{
/* generate a truth_table by transforming # of permutations into binary */
for(int i=0;i<pow((float)2,n);i++){ /*number of permutations or rows in the table */
int div=i;
int rem;
for(int j=n;j>0;j--){ /*number of bits needed for each row*/
rem=div%2;
div=div/2;
if(!rem)
cout<<"False ";
else
cout<<"True ";
}
cout<<endl;
}
}

 

posted on 2012-02-28 22:45  quantum  阅读(400)  评论(0)    收藏  举报