کد های ++c

نوشته شده توسط مهدی امینی

برنامه روش حل دستگاه معادلات خطی به روش تکراری ژاکوبی وگاوس:(درخواستی ع .علیخوانی)

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. void main(){
  5. int i,j;
  6. const int n=3;
  7. float Khata,e,temp2,temp1[n],temp=0,a[n][n],x[n],kh[n];
  8. long double b[n];
  9. clrscr();
  10. cout << "Lotfan Dar Hengame Vared Kardane Dadeha Ghotrie Ghaleb Boudane Matris ra Dar Nazar Begirid.\n";
  11. cout << "Maghadire Pishfarze X Ra Benevisid. x[0],x[1],...\n";
  12. for ( i=0 ; i<n ; i++ ){
  13. cout << "X[" << i+1 << "] = ";
  14. cin >> x[i];
  15. }
  16. cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  17. cout <<"Maghadire Matrise Pasokh ra Benevisid. B[0],B[1],...\n";
  18. for (i=0 ; i<n ; i++){
  19. cout << "B[" << i+1 << "] = ";
  20. cin >> b[i];
  21. }
  22. cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  23. cout << "Maghdire Matrise Zarayeb Ra Benevisid.a[1][1],a[1][2],...\n";
  24. for (i=0 ; i<n ;i++)
  25. for(j=0 ; j<n ; j++){
  26. cout << "a[" << i+1 << "][" <<j+1 <<"] = ";
  27. cin >> a[i][j];
  28. }
  29. cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  30. cout << "Meghdare Khata ra vared Konid : ";
  31. cin >> Khata;
  32. cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  33. do{
  34. for (i=0 ;i<n ; i++){
  35. temp2 =b[i];
  36. for (j=0 ; j<n ; j++)
  37. if (i != j )
  38. temp2 -= a[i][j]*x[j];
  39. temp1[i] = temp2 / a[i][i];
  40. }
  41. for ( i=0 ;i<n ; i++)
  42. kh[i] = temp1[i] - x[i];
  43. for(i=0 ; i<n; i++)
  44. temp += pow(kh[i],2);
  45. e = sqrt(temp);
  46. for(i=0 ; i<n ; i++)
  47. x[i] = temp1[i];
  48. temp = 0;
  49. }while( e > Khata );
  50. cout << "Javabe Dastgah Barabar Ast ba : \n";
  51. for(i=0 ; i<n ; i++)
  52. cout << "X[" << i+1 << "] = " << x[i] << endl;
  53. getch();
  54. }
  55.  

 

در خواست دوست عزیزم سعید مسئله شطرنج با الگوریتم ژنتیک سی پلاس پلاس

#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
const int chessboardsize=8; //size of chessboard
enum{empty,queen,used}; //status
struct move //movement direction
{
int x;
int y;
};
struct chessboard //chessboard type
{
int size;
int square[chessboardsize][chessboardsize];
int usedsquares;
int noqueens;
};
void setqueenmovdi(move*whatmove,chessboard*board,move*curcoor);
void main(void)
{
move curcoor; // define digonal movements
move NE;
NE.x=1;
NE.y=1;
move NW;
NW.x=-1;
NW.y=1;
move SE;
SE.x=1;
SE.y=-1;
move SW;
SW.x=-1;
SW.y=-1;
chessboard board;
board.size=chessboardsize;
srand(time(0));
while(board.noqueens!=board.size)
{
board.usedsquares=0;
board.noqueens=0;
for(int i=0;i<board.size;i++)
for(int j=0;j<board.size;j++)
board.square[i][j]=0;
while(board.usedsquares<board.size*board.size)
{
curcoor.x=rand()%board.size;
curcoor.y=rand()%board.size;
if(board.square[curcoor.x][curcoor.y]==empty)
{
board.square[curcoor.x][curcoor.y]=queen;
++board.usedsquares;
++board.noqueens;
}
else
continue;
for(int horiz=0;horiz<board.size;horiz++)
if(board.square[horiz][curcoor.y]==empty)
{
board.square[horiz][curcoor.y]=used;
++board.usedsquares;
}
for(int verti=0;verti<board.size;verti++)
if(board.square[curcoor.x][verti]==empty)
{
board.square[curcoor.x][verti]=used;
++board.usedsquares;
}
board.square[curcoor.x][curcoor.y]=queen;
setqueenmovdi(&NE,&board,&curcoor);
setqueenmovdi(&NW,&board,&curcoor);
setqueenmovdi(&SE,&board,&curcoor);
setqueenmovdi(&SW,&board,&curcoor);
}
}
cout<<endl;
for(int i2=0;i2<board.size;i2++)
{
for(int j2=0;j2<board.size;j2++)
{
cout<<board.square[i2][j2];
printf(" ");
}
cout<<endl;
}
}
void setqueenmovdi(move*whatmove,chessboard*board,move*curcoor)
{
move next;
next.x=curcoor->x+whatmove->x;
next.y=curcoor->y+whatmove->y;
if(next.x<0||next.x>board->size-1||next.y<0||next.y>board->size-1)
return;
if(board->square[next.x][next.y]==empty)
{
board->square[next.x][next.y]=used;
++board->usedsquares;
}
setqueenmovdi(whatmove,board,&next);
return;
}


کد مرتب سازی سریع quicksort

void quickSort(int x[], int left, int right)
{

        int i = left, j = right;

        int tmp;

        int pivot = x[(left + right) / 2];


        while (i <= j)
        {

                while (x[i] < pivot)

                        i++;

                while (x[j] > pivot)

                        j--;

                if (i <= j)
                {

                        tmp = x[i];

                        x[i] = x[j];

                        x[j] = tmp;

                        i++;

                        j--;

                }

        }


        if (left < j)

                quickSort(x, left, j);

        if (i < right)

                quickSort(x, i, right);

}

لطفا هر کد دیگری را که می خواهید در قسمت نظرات برای ما نوشته تا حداکثر بعد از 24 ساعت کد را در این قسمت درج کنیم

بقیه در ادامه مطالب

کد برنامه هشت وزیر

 

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>

const int m=20;
int k[m][m];
int Count=0;
int v=0 , n=0 , i=0 , j=0 , state=0;

void remove(int i,int j)
{
      int p,q;
      k[i][j]=0;
      Count--;
      for(p=0;p<n;p++)
          if(p!=i)
              k[p][j]--;
      for(p=0;p<n;p++)
        if(p!=j)
                  k[i][p]--;
      p=i+1;
      q=j+1;
     while(p<n && q<n)
      {
                    k[p++][q++]--;
     }
      p=i-1;
      q=j-1;
     while(p>=0 && q>=0)
      {
               k[p--][q--]--;
      }
     p=i+1;
      q=j-1;
     while(p<n && q>=0)
      {
               k[p++][q--]--;
      }
     p=i-1;
      q=j+1;
     while(p>=0 && q<n)
     {
                    k[p--][q++]--;
     }
}

int apply(int i,int j)
{
      int p,q;
     k[i][j]=1;
     Count++;
      for(p=0;p<n;p++)
        if(p!=i)
              k[p][j]++;
      for(p=0;p<n;p++)
        if(p!=j)
              k[i][p]++;
      p=i+1;
     q=j+1;
     while(p<n && q<n)
      {
               k[p++][q++]++;
     }
      p=i-1;
     q=j-1;
     while(p>=0 && q>=0)
      {
               k[p--][q--]++;
     }
      p=i+1;
     q=j-1;
     while(p<n && q>=0)
     {
                    k[p++][q--]++;
     }
     p=i-1;
     q=j+1;
      while(p>=0 && q<n)
     {
               k[p--][q++]++;
      }
      return 0;
}

void draw()
{
      clrscr();
     for(int p=0;p<n;p++)
     {
             for(int q=0;q<n;q++)
                 {
                     if(k[p][q]!=1)
                                   cout<<setw(3)<<'.';
                     else
                                   cout<<setw(3)<<'X';
                 }
             cout<<endl<<endl;
     }
     cout<<endl<<endl<<"Total states founded for "<<n<<"*"<<n<<" boards and "<<v<<" Queens: "<<state<<endl;
}

void check()
{
     if(Count==v)
     {
                      state++;
                 draw();
                 cout<<endl<<endl<<"Press q to exit or any key to continue...";
                 int c=getch();
                      if(c=='q')exit(0);
     }
}

void move(int p,int q)
{
     apply(p,q);
     check();
      for(int i=p;i<n;i++)
     {
             for(int j=0;j<n;j++)
                 if(k[i][j]==0)
                    move(i,j);
     }
      remove(p,q);
}

int main()
{
    cout<<"**************Queens******************"<<endl<<endl;
     cout<<"Enter size of board :";
    cin>>n;
    cout<<"Enter number of queens:";
    cin>>v;
     clrscr;
    draw();
     for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            move(i,j);
           
     clrscr;
    cout<<"Total states:"<<state<<endl;
     getch();
    return 0;
}

 

کد برنامه نمایش جدول کد اسکی

 

#include <iostream.h>

int main()
{
  for(char ch=-128;ch<127;ch++)
    cout<<"character="<<ch
         <<"\tASCII Code="<<(int)ch<<"\n";
  cout<<"character="<<ch<<"\tASCII Code="<<(int)ch<<endl;
  return 0 ;
}

 

کد برنامه فشرده سازی و کدگذاری به روش هاف من (به درخواست دوست عزیزمان آقا روح الله)

 

#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>

struct treenode{
       int data;
       int num;
       treenode *next;
       treenode *right;
       treenode *left;
}*start=NULL,*end=NULL,*p;

struct code{
       char bcode[12];
       int ch;
}coding[256];

struct tree{
        int data;
        int num;
        }atree[512];

int o=0;

int search(int i);
void insert(int i);
void insertm(struct treenode *l);
void sort();
void create();
void binary(struct treenode *n,char byte[],int i);
int searchc(int i);
void write();
void read();
void tree(struct treenode *n,int i);
int numnode=0;
int numchar=0;
char filename[25];

void main()
{
 clrscr();
 FILE *fp1,*fp2;

 cout<<"\n Enter The Location And Name Of The Source File To Compress : ";
 cin>>filename;
 fp1=fopen(filename,"r+b");
 if (fp1==NULL)
    {
       cout<<"\n Error In Open File...";
       getch();
       exit(1);
    }
  int i=getc(fp1);
  while (i!=-1)
  {
   numchar++;
   if (search(i)==-1)
      insert(i);
   i=getc(fp1);
  }
  fclose(fp1);
  sort();
  create();
  char byte[20]={0};
  binary(start,byte,0);
  tree(start,1);
  write();
  cout<<"\n\nComplete Succssfuly Coding To Code.txt\n";
  read();
  cout<<"Complete Succssfuly Encoding To Decode.txt";
  getch();
}
//*************************search******************************
int search(int i)
{
 struct treenode *h;
 h=start;
 while(h)
 {
  if (h->data==i)
  {
   h->num=h->num+1;
   return 0;
  }
  h=h->next;
 }
 return -1;
}
//**************************insert******************************
void insert(int i)
{
 p=new treenode;
 p->data=i;
 p->num=1;
 p->right=p->left=p->next=NULL;
 if (start==NULL)
 {
     start=p;
     end=p;
 }
 else
 {
     end->next=p;
     end=p;
 } }
//******************************Sort*******************
void sort()
{
 struct treenode *h1,*h2,*n2,*right,*left;
 int d,n;
 n2=start;
 while(n2)
 { h1=start;
   h2=start->next;
  while(h2)
  {
    if (h1->num > h2->num)
    {
      d=h1->data;
      n=h1->num;
      right=h1->right;
      left=h1->left;
      h1->data=h2->data;
      h1->num=h2->num;
      h1->right=h2->right;
      h1->left=h2->left;
      h2->data=d;
      h2->num=n;
      h2->right=right;
      h2->left=left;
    }
     h1=h2;
     h2=h2->next;
    }
     n2=n2->next;
 } }
//****************Create*******************************
void create()
{
  struct treenode *h;
  while (start->next)
  {
   int i1,i2;
   p=new treenode;
   p->left=start;
   p->right=start->next;
   p->num=start->num+start->next->num;
   p->data=-1;
   p->next=NULL;
   h=start;
   start=start->next->next;
   h->next->next=NULL;
   h->next=NULL;
   insertm(p);
   sort();
  }}
//********************Insertm****************************
void insertm(struct treenode *l)
{
 if (start==NULL)
 {
     start=l;
     end=l;
 }
 else
 {
     end->next=l;
     end=l;
 } }
//********************Binary****************************
void binary(struct treenode *n,char byte[],int i)
{
 if (n->data==-1)
    {
      char b1[20]={0},b2[20]={0};
      strcpy(b1,byte);
      strcpy(b2,byte);
      b1[i]='1';
      binary(n->right,b1,i+1);
      b2[i]='0';
      binary(n->left,b2,i+1);
     }
   else
     {
       cout<<"Char :"<<(char)n->data<<" Byte : "<<byte<<"\n";
       strcpy(coding[o].bcode,byte);
       coding[o++].ch=n->data;
     }
}
//*********************Coding*******************************
void write()
{
  FILE *fp1,*fp2;
  fp1=fopen(filename,"r+b");
  fp2=fopen("Code.txt","w+b");
  //**************************************************************
  int i=1;
  while (i<=numnode)
  {
    fprintf(fp2,"%d",atree[i].data);
    i++;
  }
  //*****************************************************************
 i=getc(fp1);
 int j=0,place=1;
 unsigned char bytebuf=0;
 while (i!=-1)
  {
   j=searchc(i);
   int y=0;
   while (coding[j].bcode[y]) {
      if (coding[j].bcode[y]=='1')
          bytebuf |= place;

      if (place==128)
      {
     putc(bytebuf,fp2);
     place=1;
     bytebuf=0;
       }
       else
     place<<=1;
       y++;
      }
   i=getc(fp1);
  }
  if (place<=128 && place !=1) putc(bytebuf,fp2);
  fclose(fp1);
  fclose(fp2);
}
//********************searchcode***************************
int searchc(int i)
{
  int j=0;
  while (j<o)
      if (coding[j].ch==i)
           return j;
      else
           j++;
}
//**********************Encode*****************************
void read()
{
 FILE *fp1,*fp2;
 fp1=fopen("Decode.txt","w+b");
 fp2=fopen("Code.txt","r+b");
 //************************************************
 int i=1,a;
  while (i<=numnode)
  {
    fscanf(fp2,"%d",&a);
    i++;
  }
 //************************************************
 i=getc(fp2);
 int j=0,place=1;
 struct treenode *n;
 unsigned char bytebuf=0;
 while (i!=-1)
 {
   n=start;
   while (n->data==-1)
    {
      int x=(place & i)?1:0;
      if (x==1)
    n=n->right;
      else
    n=n->left;
      if (place==128)
     {i=getc(fp2);
      place=1; }
      else
      place<<=1;
     }
   if (j++<numchar)
     putc(n->data,fp1);
  }
  fclose(fp1);
  fclose(fp2);
}
//*********************************************************
void tree(struct treenode *n,int i)
{
 atree[i].data=n->data;
 atree[i].num=n->num;
 numnode=i;
 if (n->left!=NULL)
    tree(n->left,2*i);
 if (n->right!=NULL)
    tree(n->right,2*i+1);
}

کد برنامه مرتب سازی انتخابی

 

void selectionSort(int arr[], int len)
{
     int i, j, minIndex, tmp;
     for (i = 0; i < len - 1; i++)
    {
         minIndex = i;
          for (j = i + 1; j < len; j++)
                if (arr[j] < arr[minIndex])
                     minIndex = j;
        if (minIndex != i)
        {
                tmp = arr[i];
            arr[i] = arr[minIndex];
                arr[minIndex] = tmp;

        }

    }

}

کد برنامه مرتب سازی حبابی

 

void BubbleSort(int temp[], int len)
{
    int i, j, item;
    for(i=len-1;i>0;i--)
        for(j=0;j<i;j++)
            if(temp[j]>temp[j+1])
            {
                item=temp[j];
                temp[j]=temp[j+1];
                temp[j+1]=item;
            }
}

کد برنامه برج هانوی (ساده بدون گرافیک)

 

#include <iostream.h>
#include <stdio.h>
#include <conio.h>

void tower(int,char,char,char); /*prototype*/
int main()
{
    int ndisk;
    clrscr();
    cout<<"\n Enter number of disks <<<::: ";
    cin>>ndisk;
    tower(ndisk,'A','B','C');  /*Calling Function*/
    getch();
    return 0;

} /* End of program */

/********************************************/

// src = Source | aux = Auxiliry | dest = Destination
void tower(int topN, char src,char aux,char dest)
{
    if(topN == 1)
    {
            cout<<"\n Disk 1 from "<<src<<" to "<<dest;
    }
    else
    {
        tower(topN-1,src,dest,aux); //src to aux
        cout<<"\n Disk "<<topN<<" from "<<src<<" to "<<dest;
        tower(topN-1,aux,src,dest); //aux to dest
    }
}

کد برنامه برج هانوی (گرافیکی )فقط نسخه ی گرافیکی و اجرائی

برای دانلود روی عکس زیر کلیک کنید.

 

کد نمایش مقسوم علیه عدد ورودی

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    unsigned long int n; // Input number
    register unsigned long int i; // Counter
    unsigned long int sum=0;
    cout<<"\nYek adad vared konid: ";
    cin>>n;
    cout<<endl<<endl;
    cout<<"1"<<endl;
    for(i=2;i<=(n/2);i++){
        if(n%i==0){
            cout<<i<<endl;
            sum=sum+i;
        } // End of if
    } // End of for
    cout<<n<<endl;
    cout<<"\n\nJam'e maghsom aleih haye "<<n<<" mishavad "<<sum;

    getch();
}
//end

کد جستجوی دودویی یا همان باینری

 

*/
int binarySearch(int arr[], int len, int pat)
{
    int mid, low=0, high=len-1;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(pat<arr[mid])
            high=mid-1;
        else if(pat>arr[mid])
            low=mid+1;
        else
            return mid;
    }
    return -1;
}

کد برنامه کشیدن دو لوزی در کنار هم

#include <iostream.h>
#include <conio.h>
void fasele(int n){
for(int i=1;i<=n;i++)
cout<<" ";
return;
}
//---------------------
int main(){
int n;
cout<<"Enter n\n";
cin>>n;
int a=n,b=n-1,c=n-1;
for(int i=1;i<=2*n-1;i+=2){
fasele(a);
 for(int j=1;j<=i;j++)
 cout<<"*";
 fasele(b);
 fasele(c);
 for(int k=1;k<=i;k++){
 
 cout<<"*";}
 cout<<endl;
 a--;
 b--;
 c--;
 }
int d=2,e=1,f=1;
for(int i=2*n-3;i>=1;i-=2){
 fasele(d);
 for(int j=1;j<=i;j++)
 cout<<"*";
 fasele(e);
 fasele(f);
 for(int k=1;k<=i;k++)
 cout<<"*";
 cout<<endl;
 e++;
 f++;
 d++;
 }
cout<<"---------------------------------------------------\n\n";
cout<<" Designer : Salar Ashgi\n";
 getch();
 }

 

کد برنامه تبدیل کارکتر به کد اسکی

 

#include <iostream.h>
#include <conio.h>
int main()
{
cout<<"faghat yek char vared konid :\t";
char s;
cin>>s;
//clrscr();
        cout<<"ascii code of "<<s<<" is ";
        cout<<(int)s;
getch();
return 0;

 

کد برنامه تفکیک اعداد از حروف

 

#include <iostream.h>
#include <conio.h>
void char_int(long int);
int main()
{
cout<<"jomle khod ra vared namaied :\t";
long int a1;
char_int(a1);

}
//function stated
void char_int(long int a1)
{
   long int a = 0 , i = 0 , co_num = 0 , n = 1 , num1 = 0;
   char *al , ss;
   al = new char[a];
      while(ss = cin.get() , ss != '\n')
                 {
                        if(ss == ' ')
                            continue;
                       if(!((int)ss < 48 || (int)ss > 57)) //scii code of numbers 1 to 9
                                {
                                    al[a] = ss;
                                    a++;
                                }
                  }
     cout<<a <<'\n';
for(i = a-1; i >= 0; i--) //string to integer
   {
           co_num = (((int)al) - 48);
           co_num = co_num * n;
           num1 += co_num;
           n *= 10;
   }
  cout<<num1;
getch();
}

 

کد برنامه بدست آوردن معکوس یک عدد

 

#include<iostream>
using namespace std;
int main()
{
 int n,r,m=0;
 cout<<"lotfan add ra vared konid :  ";
 cin>> n;
 while(n!=0)
 {
 r=n%10;
 m=(m*10)+r;
 n=n/10;
 }
cout<<"maghlob is :"<<m<<"\n";
return 0;
}

کد 8 وزیر برای ویژوال بیسیک 6  vb

 

DIM a(1 TO 8) AS INTEGER
CLS
arzesh = 0

PRINT "vazir"


FOR a = 1 TO 8
   a(1) = a
 
 
   FOR b = 1 TO 8
     a(2) = b
                           FOR i = 1 TO 1
                           
                              FOR j = 1 TO 2
                                 IF i = j THEN j = j + 1
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i
    
      FOR c = 1 TO 8

                          IF arzesh <> 0 THEN
                          arzesh = 0
                         EXIT FOR

                          END IF

         a(3) = c
                           FOR i = 1 TO 2
                          
                              FOR j = 1 TO 3
                                 IF i = j THEN j = j + 1
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i
         FOR d = 1 TO 8
                          IF arzesh <> 0 THEN
                          arzesh = 0
                         EXIT FOR

                          END IF
          
            a(4) = d

                           FOR i = 1 TO 3
                         
                              FOR j = 1 TO 4
                                 IF i = j THEN j = j + 1
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i

            FOR e = 1 TO 8

                          IF arzesh <> 0 THEN
                          arzesh = 0
                         EXIT FOR

                          END IF
               a(5) = e
                         
                           FOR i = 1 TO 4
                         
                              FOR j = 1 TO 5
                                 IF i = j THEN j = j + 1
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i
             
               FOR f = 1 TO 8
                
                          IF arzesh <> 0 THEN
                          arzesh = 0
                         EXIT FOR

                          END IF
                  a(6) = f
                           FOR i = 1 TO 5
                         
                              FOR j = 1 TO 6
                                 IF i = j THEN j = j + 1
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i
                  FOR g = 1 TO 8
                     a(7) = g
                          IF arzesh <> 0 THEN
                          arzesh = 0
                         EXIT FOR

                          END IF
                   
                           FOR i = 1 TO 6
                         
                              FOR j = 1 TO 7
                                 IF i = j THEN j = j + 1
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i
                   
                   
                     FOR h = 1 TO 8
                          IF arzesh <> 0 THEN
                          arzesh = 0
                         EXIT FOR

                          END IF
                         
                           a(8) = h
                         
                            'FOR s = 1 TO 8
                           ' PRINT a(s);
                            'NEXT
                           ' PRINT
                         
                           FOR i = 1 TO 7
                            
                              FOR j = 1 TO 8
                                 IF i = j THEN j = j + 1

                                 IF j = 9 THEN EXIT FOR
                                 arzesh = (ABS(i - j) = ABS(a(i) - a(j))) OR (a(i) = a(j))
                               
                                 IF arzesh = -1 THEN EXIT FOR
                              NEXT j
                            
                              IF arzesh = -1 THEN EXIT FOR
                          NEXT i
                          IF arzesh = 0 THEN
                                            x = x + 1
                                            PRINT
                                            PRINT
                                            PRINT
                                            PRINT x,
                          FOR v = 1 TO 8
                                PRINT a(v);
                          NEXT
                         
                         mnb$ = INPUT$(1)
                          ELSE
                        
                          arzesh = 0
                         END IF

 NEXT h
 NEXT g
 NEXT f
 NEXT e
 NEXT d
 NEXT c
 NEXT b
 NEXT a