#include<iostream> #include<conio.h> #include<string.h> using namespace std; int power(int a,int b) { int k=1; for(int i=0;i<b;i++) k=a*k; return k; } void print(char aray[][10],int s1,int ar[],int s2) { int h=1; for(int i=0;i<s1;i++) { cout<<h<<".{"; for(int j=0;j<s2;j++) { if(aray[i][j]=='1') { cout<<ar[j]<<","; } } cout<<"}"<<endl; h++; } } int main() { int size; cin>>size; int g=size; int ar[10]; for(int i=0;i<size;i++) cin>>ar[i]; int s1; s1=power(2,size); char aray[50][10]; strcpy(aray[0],"0"); strcpy(aray[1],"1"); int b=0; int j=0; while(power(2,j+1)<s1) { b=0; j++; for(int i=0;i<power(2,j);i++) { for(int l=0;l<2;l++) { if(l==0) { strcpy(aray[b+power(2,j)],aray[b]); strcat(aray[b+power(2,j)],"0"); } else strcat(aray[b],"1"); } b++; } } print(aray,s1,ar,size); cout<<"press any key for quit"<<endl; getch(); }
#include<stdio.h> #include<conio.h> #include<iostream.h> #define EOLN '\n' void main(){ void reverse(void); clrscr(); cout<<"Please Write Your Text Below :"<<'\n'; reverse(); } void reverse (void) { char c; if ((c=getchar()) != EOLN) reverse(); putchar(c); return; }
/* ============== Program Description ============= */ /* program name : fibtab.cpp */ /* compute a valeu of a position in fib tab */ /* ================================================== */ #include <iostream.h> #include <conio.h> int fib (int n); main() { int n; clrscr(); cout<<"enter a position -->"; cin>>n; cout<<"the position "<<n<<" in fibonachi is "<<fib(n); getch(); return 0; } //end main //***************************** int fib (int n) { if (n<=1) return n; else return fib(n-2)+fib(n-1); }
/* ============== Program Description ============= */ /* program name : retabfact.cpp */ /* compute fact with return tab */ /* ================================================== */ #include <iostream.h> #include <conio.h> int fact (int n); main() { int n; clrscr(); cout<<"enter a num -->"; cin>>n; cout<<n<<"!= "<<fact(n); getch(); return 0; } //end main //***************************** int fact (int n) { int f=0; if ((n==0)||(n==1)) return 1; else f=n*fact (n-1); return f; } </body> </html>
/* ============== Program Description ============= */ /* program name : bayretab.cpp */ /* compute bayneri with return tab */ /* ================================================== */ #include <iostream.h> #include <conio.h> int bay (int n); main() { int n; clrscr(); cout<<"enter a number -->"; cin>>n; cout<<"the barneri of "<<n<<" is "; bay (n); getch(); return 0; } //end main //***************************** int bay (int n) { if (n>0) { bay (n/2); cout<<n%2; } }