برنامه های درخواستی

حل معادله نیوتن رافسون

حل معادله نابجایی

حل معادله از طریق منصف

ضرب ماتریس

حل معادله از راه سیمپسون

محاسبه انتگرال از راه ذوزنقه

محاسبه انتگرال دو بخشی

تابع چند جمله ای ها

طراحی ساعت دیجیتالی و آنالوگی

حل معادله نیوتن رافسون

#include
#include
#include
void main(void)
 {


  float h,x1,f,f1,g,a,b,x;
  int i,conter;


 top: clrscr();
      printf(" \n******************************in file**************************");
      printf("\ninput [a,b]");
      printf("\ninput a=");
      scanf("\n%f",&a);
      printf("input b=");
      scanf("\n%f",&b);
      printf("\nbaseh f(x)=>    [%f,%f]",a,b);
      x=a;
/****************   f(x)   ****************/
      f=x*pow(2,x)-1;
      g=x*x*2;
/*******************************************/
      printf("\nf(a)=%f",f);
      x=b;
/*****************   f(x)   ***************/
      f1=x*pow(2,x)-1;
/*******************************************/
      printf("\nf(b)=%f",f1);
      if ((f1*f)<0)
        printf("\nIF ONE TRUE");
      else
       {
   printf("\n IF ONE FALSE --F(a)F(B)<0--");
   goto top;
       }
//****************************************************************
      printf("\ninput x1:=");
      scanf("%f",&x1);
      printf("\nnumber repeter :=");
      scanf("%d",&conter);
      printf("\n************************out file****************************");

      for(i=1;i<=conter;i++)
    {
        h=x1-(f/g);
        printf("\n%f ",h);
        x1=h;
    }

      getch();
}

حل معادله از طریق منصف

#include "stdio.h"
#include"conio.h"
#include
float w1(float q);
float w11(float q);
int n=0,zz;
main()
{
 float x[100];
 int i,j;
 float a1;
 clrscr();
  printf("\n\n\n                    ِّ¨êگ¤  ‹  ِ—ّ‏÷  ü¢¢ن  –‘“¨‘ںُ ù¥ّ¤•");
  printf("  \n\n\n                                  : §‏ّ÷ ùُ‘÷¤“");
  printf("  \n\n\n                        üُ‘َè ¢ُںگ");
  printf("\n\n\n plese input number for sqrt ==>");
  scanf("%i",&zz);
  a1=sqrt(zz);
 x[n]=a1;
 printf("     x0 : %f",x[n]);
 n++;
 for(i=0;i<4;i++)
 {
   x[n]=x[n-1] - w1(x[n-1]) / w11(x[n-1]);
   printf("\n      x%i : %f",i+1,x[i+1]);
   n++;
 }
 getch();
 return 0;
}
//************************
float w1(float q)
{ float bb;
 bb=(q*q)-zz;
 return(bb);
}
//********************
float w11(float q)
{
  float bb;
  bb=2*q;
 return(bb);
 }

 

حل معادله از راه سیمپسون

# include "stdio.h"
# include "conio.h"
main()
{
float   a,b,h,i1,h2,n,i2,x,i3,i;
float   w1,w2,w3,k;
int j;
clrscr();
printf ("enter 1 number for A:");
scanf ("%f",&a);
printf ("enter 1 number for B:");
scanf ("%f",&b);
printf ("enter 1 number for eps:");
scanf ("%f",&h);
n=(b-a)/ h;
printf("n:= %f",n);
h2=h*2;
i1=(1/(1+a*a))+(1/(1+b*b));
i2=0;
i3=0;
x=a+h;
j=1;
while (j<=(n/2))
{
i2=i2+(1/(1+x*x));
x=x+h2;
j=j+1;
}
x=a;
j=1;
while (j<=((n/2)-1))
{
x=x+h2;
i3=i3+(1/(1+x*x));
j=j+1;
}
w1=h/3;
w2=4*i2;
w3=2*i3;
i=(w1*(i1+w2+w3));
printf ("\n               (f(1)  +   f(2)    +    f(3)   +    f(4)   +   f(5))");
printf("\n---------------------------------------------------------------------------");
printf ("\ns(h)=(h/3)*(f(%f",a,")");
for (j=1;j<=4;j++)
{
printf ("+");
k=j*h;
printf("f(%f",k);
printf(")");
}
printf(")=%f",i);
getch();
}


 

ضرب ماتریس


#include"stdio.h"
#include"conio.h"
main()
{
clrscr();
int a[2][3] , b[3][4],c[2][4],i,k,j;
for (j=0;j<2;j++)
for (i=0;i<3;i++)
{
printf("input a[%i][%i]",j,i);
scanf("%d",&a[j][i]);
}
for (j=0;j<3;j++)
for (i=0;i<4;i++)
{
printf("input b[%i][%i]",j,i);
scanf("%d",&b[j][i]);
}
for(j=0;j<2;j++)
for(i=0;i<4;i++)
{
c[j][i]=0;
for(k=0;k<3;k++)
c[i][j]=c[j][i]+a[j][k]*b[k][j];
}
printf("%d,c[i][j]");
printf("\n");
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
printf("%d  ",c[j][i]);
printf("\n");
}
getch();
return 0;
}

محاسبه انتگرال از راه ذوزنقه

#include
#include
#include
#include
const float pi=3.141592653569793238462643;
float gtt();
float sin1(float x);
float cos1(float x);
float powe(float x,int y);
char ch;
float va1=0,va2=0;

main()
{
  clrscr();
  va1=gtt();
do
{
  switch(ch)
     {
 case '+':
 clrscr();
 va2=gtt();
 va1=va1+va2;
 break;
 case '-':
 clrscr();
 va2=gtt();
 va1=va1-va2;
 break;
 case '*':
 clrscr();
 va2=gtt();
 va1=va1*va2;
 break;
 case '/':
 clrscr();
 va2=gtt();
 va1=va1/va2;
 break;
 case 's':
 clrscr();
 va1=(va1*3.14)/180;
 va1=sin1(va1);
 break;
 case 'c':
 clrscr();
 va1=(va1*3.14)/180;
 va1=cos1(va1);
 break;
 case 't':
 clrscr();
 va1=(va1*3.14)/180;
 va1=sin1(va1)/cos1(va1);
 break;
 case 'o':
 clrscr();
 va1=(va1*3.14)/180;
 va1=cos1(va1)/sin1(va1);
 break;
 case 13:
 clrscr();
 printf ("\n %f",va1);
 break;
      }
}
while (ch!=27);
}

/*****************************get*********/
float gtt()
{
  float v;
  int i=0;
  char h='w';
  char s[20];
  strcpy (s,"");

   do
    {
 ch=getche();
 if (ch=='0'|| ch=='1' || ch=='2'|| ch=='3'|| ch=='4' || ch=='5'
 ||ch=='6'|| ch=='7' || ch=='8'|| ch=='9')
 {
 s[i+1]=NULL;
 s[i]=ch;
 i++;
   }
 if (ch=='+'|| ch=='-' || ch=='*'|| ch=='/'|| ch=='s'|| ch=='c'|| ch=='t'|| ch=='o'|| ch==13) h=13;
    } while(h!=13);
     v=atof(s);
     return(v);
    }

/**************sin**************/
float sin1(float x)
{
 float ss;
 ss=(x-(powe(x,3)/6)+(powe(x,5)/120)-(powe(x,7)/5040)+(powe(x,9)/362880));
 return(ss);
 }
/**************cos**************/
float cos1(float x)
{
 float ss;
 ss=(1-(powe(x,2)/2)+(powe(x,4)/24)-(powe(x,6)/720)+(powe(x,8)/40320));
 return(ss);
 }
/**************tavan**************/
float powe(float x,int y)
{
  int i;
  float tt=1;
for (i=1;i<=y;i++)
tt=tt*x;
return(tt);
}

میانگین در آرایه

#include "stdio.h"
#include "conio.h"
main()
{
int a[10],i,c;
clrscr();
for(i=0; i<10; i++)
{
printf("input no  (%d)\n ",i+1);
scanf("%i",&a[i]);
}
for(i=0;i<10;i++)
c=c+a[i];
printf("\n avg: %d",c);
getch();
}

تابع چند جمله ای ها

#include
#include

long int c[2][100]={0};
int k=0;

void add(long int x[2][100],long int y[2][100]);
void type(long int a[2][100],int l);
void search(long int a[2][100],int h);

int main()
{

 int i=0,j=0,l=-1,r=-1,w;
 long int a[2][100]={0},b[2][100]={0},e[2][100]={0},f[2][100]={0};

 clrscr();
 printf("\n\n\t   A(x) :a(n)X^e(n) + a(n-1)X^e(n-1) + ... + a(1)X^e(1) \n");
 printf("\n\t\t\t For exit : ( 0 & 0 ) ");
 printf("\n\t***********************************************************\n\n");
 do
 {
    printf(" Coeff  %i  of A(x) : ",i+1);
    scanf("%li",& a[1][i]);
    printf("\n Square  %i  of A(x) : ",i+1);
    scanf("%li",& a[0][i]);
    printf(" ----------------------------------------------------------------------------\n");
    i++;l++;
 }while(a[1][i-1]!=0 );
 search(a,l);
 printf("\n\n\tA(x): ");
 type(a,l);
 printf("\n\n\n\n\t\t     Press any key to continue ...");
 getch();
 clrscr();
 printf("\n\n\t   B(x) :b(n)X^e(n) + b(n-1)X^e(n-1) + ... + b(1)X^e(1) \n");
 printf("\n\t\t\t For exit : ( 0 & 0 ) ");
 printf("\n\t***********************************************************\n\n");
 do
 {
    printf(" Coeff  %i  of B(x) : ",j+1);
    scanf("%li",& b[1][j]);
    printf("\n Spuare  %i  of B(x) : ",j+1);
    scanf("%li",& b[0][j]);
    printf(" ----------------------------------------------------------------------------\n");
    j++;r++;
 }while(b[1][j-1]!=0);
 search(b,r);
 printf("\n\n\tB(x): ");
 type(b,r);
 printf("\n\n\n\n\t\t     Press any key to continue ...");
 getch();
 clrscr();
 printf("  ***************************************************************************");
 printf("\n\n    A(x) =");
 type(a,l);
 printf("\n\n  ***************************************************************************");
 printf("\n\n    B(x) =");
 type(b,r);
 add(a,b);
 printf("\n\n  ***************************************************************************");
 printf("\n\n    A(x) + B(x) =");
 type(c,k);
 for(i=0;i {
     c[1][i]=0;
     c[0][i]=0;
 }
 for(i=0;i {
     for(j=0;j     {
 k=0;
 e[1][j]=a[1][i]*b[1][j];
 e[0][j]=a[0][i]+b[0][j];
     }
     add(e,f);
     for(w=0;w     {
 f[1][w]=c[1][w];
 f[0][w]=c[0][w];
     }
 }
 printf("\n\n  ***********************************************************");
 printf("\n\n    A(x) * B(x) =");
 type(c,k);
 printf("\n\n  ***************************************");
 printf("\n\n\n\n\n\t\t\t Press any key to exit ...");
 getch();
 return(0);
}

/*************** FUNCTION ADD *****************************/

void add(long int x[2][100],long int y[2][100])
{

  int i=0,j=0;

  do
  {
  if(x[0][i]==y[0][j])
   {
     c[0][k]=x[0][i];
     c[1][k]=x[1][i]+y[1][j];
     k++;i++;j++;
   }
  if(x[0][i] > y[0][j])
   {
     c[0][k]=x[0][i];
     c[1][k]=x[1][i];
     k++;i++;
   }
  if(x[0][i] < y[0][j])
   {
     c[0][k]=y[0][j];
     c[1][k]=y[1][j];
     k++;j++;
   }
  }while(x[1][i]!=0 || y[1][j]!=0);
}

/********* FUNCTION TYPE ******************/

void type(long int a[2][100],int l)
{

   int i=0;

   if(a[1][0]==0)
       printf(" 0");
   while(a[1][i]!=0)
   {
    for(i=0;i    {
    if(a[1][i]>0 && a[1][i]!=a[1][0])
 printf(" +");
    if(a[0][i]==1 && a[1][i]==1)
 printf(" x");
    if(a[0][i]==1 && a[1][i]==-1)
 printf(" - x");
    if(a[1][i]==1 && a[0][i]!=0 && a[1][i]!=0 && a[0][i]!=1)
 printf(" x^%li",a[0][i]);
    if(a[1][i]==-1 && a[0][i]!=0 && a[1][i]!=0 && a[0][i]!=1)
 printf(" - x^%li",a[0][i]);
    if(a[0][i]==0 && a[1][i]!=0)
 printf(" %li",a[1][i]);
    if(a[0][i]==1 && a[1][i]!=0 && a[1][i]!=1 && a[1][i]!=-1)
 printf(" %lix",a[1][i]);
    if(a[1][i]!=1 && a[1][i]!=-1 && a[0][i]!=0 && a[1][i]!=0 && a[0][i]!=1)
 printf(" %lix^%li",a[1][i],a[0][i]);
    }
   }
}

/************************** FUNCTION SEARCH ***************/

void search(long int a[2][100],int h)
{

 int i,j,g,item1,item2;

 for(i=h;i>0;i--)
    for(j=0;j       if(a[0][j]       {
   item1=a[0][j];
   a[0][j]=a[0][j+1];
   a[0][j+1]=item1;
   item2=a[1][j];
   a[1][j]=a[1][j+1];
   a[1][j+1]=item2;
       }

 for(i=0;i    for(j=0;j       if(a[0][j]==a[0][j+1])
       {
    a[1][j]+=a[1][j+1];
    for(g=j+1;g    {
        a[1][g]=a[1][g+1];
        a[0][g]=a[0][g+1];
    }
       }
}

/*********** END PROGRAM *****************/

برنامه های درخواستی شما

نمایش فایل تصویری در سی pcx

نمایش فایل bmp

mouse function

برنامه کتابخانه

infix , postfix ,perfix

جدول هش hash در سی

بازی در سی

فشرده سازی در سی

فارسی ساز در سی

شبیه ساز ایجاد فولدر

برنامه حقوق و دستمزد

ماشین حساب

شبیه ساز اتوکد با سی

محاسبه ماکسیمم و میانگین در آرایه

برنامه 118

تابع تولید کادر در صفحه

تبدیل عدد فارسی به عدد صحیح

 یک هدر header (فارسی ساز )

تابع ماتریس واروون

برنامه تشخیص همبند یا ناهمبند بودن گراف و همیلتونی

برنامه معدل نمرات دانشجویان

برنامه کتابخانه

#include
#include
#include
#include
#include
#include
typedef
 struct dta{
     char book[30];
     writer[30];
     code[30];
     namb[30];
     publish[30];
   struct dta*link;
   } data;
   typedef
     struct{
       char book[30];
       id1;
       writer[30];
       id2;
       code[30];
       id3;
       numb[30];
       id4;
       publish[30];
       } bnk;
 data *new,*first,*this;
 bnk bank;
void zero_bank(void)
  {
    register int cnt;
    for (cnt=0;cnt    *(char*)(bank+cnt)="'\o";
    }
    void load(void)
    {
    FILE *fp;
     if((fp=fopen("data.bnk","r"))=null)
        {
        printf("\n\n new file.");
        retern;
        }
    fread (&bank,sizeof(bank),1,fp);
    while(!feof(fp))
        {
  if ((new_=mblloc(sizeof(data)))==null
  {
   printf("\n\rnot enough memory ...");
   fclose(fp);
   return;
   }
     new_->link=null;
     if (frist==null)  frist=this_=new_;
     else
 {
 this_=frist;
 while(this_->link!=null)this_=this_->link;
 this_->link=new_;
 this_=new_;
 }
    strcpy(this_->code,bank.code);
    strcpy(this_->book,bank.book);
    strcpy(this_->writer,bank,writer);
    strcpy(this_->numb,bank.publish);
    strcpy(this_->publish,bank.publish);
    fread(&bank,sizeof(bank),1,fp);
       }
    fclose(fp);
     }
    void save(void)
      {
 FILE *fp;
 if((fp=fopen("data.bnk","w"))=null)
   {
   printf("\n\ncan not open file.");
   retern;
   }
  this_=frist;
       while (this!=null)
       {
 zero_bank();
 strcpy(bank.cod,this_->code);
 strcpy(bank.book,this_->book);
 strcpy(bank.writer,this_->writer);
 strcpy(bank.numb,this_->numb);
 strcpy(bank.publish,this_->publish);
 bank.id1=bank.id2=bank.id3=bank.id4='*';
 fwrite(&bank,sizeof(bank),1,fp);
 this_=this_->link;
 }
     fclose(fp);
     }
     void enter(void)
       {
  if ((new_=mblloc(sizeof(data)))==null)
     {
      printf("\n\rnot enough memory...");
      reternl;
      }
      new_->link=null;
      if (frist==null)  frist=this_=new_;
       else
  {
   this_=frist;
   while(this_->link!=null)this_=this_-link;
   this_->link=new_;
   this_=new-;
   }
   printf ("\n enter book code:");
   gets(this_->code);
  printf ("\n enter book name:");
  gets(this_->book);
  printf ("\n enter book writer name:");
  gets (this_->writer);
  printf ("\n enter numberof this book:");
  gets (this_->numb);
  printf ("\n enter publisher name:");
  gets (this_->publish);
  printf ("\n \n\n\r\t\tpress any  key ...\n");
  }
    void display(void)
  {
  int i;
  if(first==null)
  {
  printf("\n\t listis empty.");
  printf("\n\t press any key to continue...");
  getch();
  retern;
  }
  else
     {
      this_=first;
      while (this_!=null)
        {
        printf("\nbook code:");
        printf("%s",this_->code);
        printf("\nbook name:  :");
        printf("%s",this_->book);
        printf("\n book write name:");
        printf("%s",this_->write);
        printf("\n number of this book:");
        printf("%s",this_->numb);
        printf("\n publuisher name:");
        printf("%s",this_->publish);
        printf("\n\n\n\r\t\tpress any key ...\n\n");
        this_=this_->link;
        getch();
        }
  }
  getch();
  }
  void delete_(void)
  {
  char code[30];
  printf("\n\tentre book code for delete:");
  gets(code);
  this_=first;
  while (this_!null)
  {
  if(!strcmp(this_->code,code))
  {
  if(this_==frist) frist=this_->link;
  else               new_->link=_->link;
  free(this_);
  return;
  }
  new_=this_;
  this_=this_->link;
     }
      printf("\n\n\t\t record not found.");
       sleep(3);
      }
      void  sortbycode(void)
      {
        data *q,*p,*q1;
        data *frist2;
        frist2=null;
        q1=frist;
        while(q1!=null)
        {
        new_=mblloc(sizeof(data));
        strcpy(new_->code,q1->code);
        strcpy(new_->book,q1->book);
        strcpy(new_->writer,q1->writer);
        strcpy(new_->numb,q1->numb);
        strcpy(new_->publish,q1->publish);
        if(frist2==null)
  {
  new_->link=null;
  frist2=new_;
  p=q=frist2;
  first->link=null;
  }
  else
    {
    if (atoi(new_->code)code))
     {
        new_->link=first2;
        first2=new_;
        p=q=first2;
        }
        else
        {
        p=q=frist2;
        while(atoi(p->code)code)&&p!=null)
        {
        q=p;
        p=p->link;
  }
      if(p==null)
       {
       new_->link=null;
       q->link=new_;
       new_->link=null;
       }
       else
       {
       new_->link=p;
       q->link=new_;
       }
     }
   }
      q1=q1->link;
      }
    frist=frist2;
    }
    void sortbyname(void)
    {
     data  *q,*p,*q1;
     data *first2;
     first2=null;
     q1=frist;
     while(q1!=null)
     {
        newe_=mblloc(sizeof(data));
        strcpy (new_->code,q1->code);
        strcpy (new_->book,q1->book);
        strcpy (new_->writer,q1->writer);
        strcpy (new_->numb,q1->numb);
        strcpy (new_->publish,q1->publish);
        if(frist==null)
   {
   new_->link=null;
   frist2=new_;
   p=q=frist2;
   frist->link=null;
   }
       else
       {
       if(new_->book[0]book[0])
        {
        new_->link=frist2;
        first2=new_;
        q=p=frist2;
        }
  else
  {
  p=q=frist2;
  while(p->book[0]book[0]&&p!=null)
  {
  q=p;
  p=p->link;
  }
     if (p==null)
      {
      new_->link=null;
      q->link=new_;
      new_->link=null;
      }else
      {

      new_->link=p;
      q->link=new_;
      }
    }
  }
  q1=q1->link;
       }
       frist=frist2;
     }
     void sort by publish(void)
       {
       data *q,*p,*p1;
       data *frist2;
       frist2=null;
       q1=frist;
       while(q1!=null)
       {
       new_=mblloc(sizeof(data));
       strcpy (new_->code,q1->code);
       strcpy(new_->book,q1->book);
       strcpy(new_->writer,q1->writer);
       strcpy(new_->numb,q1->numb);
       strcpy(new_->publish,q1->publish);
       if (first2==null)
 {
 new_->link=null;
  frist2=new_;
  p=q=frist2;
  frist->link=null;
  }
  else
  {
  if(new_->publish[0]publish[0])
   {
   new_->link=frist2;
   first=new_;
   q=p=frist2;
   }
   else
   {
    p=q=frist2;
    while(p->publish[0]publish[0]&&p!=null)
       {
       q=p;
       p=p->link;
       }
     if (p==null)
       {
       new_->link=null;
       q->link=new_;
       new_->link=null;
       }
       else
       {
       new_->link=p;
       q->link=new_;
       }
    }
   }
   q1=q1->link;
  }
  frist=frist2;
  }
   viod sortbywriter(viod)
       {data  *q,*p,*q1;
       data *frist;
       frist2=null;
       q1=frist;
       while(q1!=null)
       new_=mblloc(sizeopf(data));
       strcpy(new_->code,q1->code);
       strcpy(new_->book,q1->book);
       strcpy(new_->writer,q1->writer);
       strcpy(new_->numb,q1->numb);
       strcpy(new_->publish,q1->publish);
       if (frist2==null)
       {
       new_->link=null;
       frist2=new_;
       p=q=frist2;
       frist2->link=null;
       }
       else
       {
       if (new_->writer[0]writer[0])
       {
       new_->link=frist;
       frist=new_;
       q=p=frist2;
       }
       else
       {
       p=q=frist2;
        while(p->writer[0]writer[0]&&p!=null)
      {
      p=q;
      p=p->link;
       }
        if(p=null)
       {
       new_->link=null;
       q->link=new_;
       new_->link=null;
       }
       else
       {
        new_->link=p;
        q->link=new_;
        }
     }
        }
        q1=q1->link;
        }
        frist=frist2;
        }
   void edit(void)
   {
   char code[30];
   char bool=0;
   new_=this_=frist;
   printf("\n\tentr code:");
   gets(code);
   while(this_!=null)
        {
        if(!strcpy(this_->code,code))
     printf("\n book code :");
     printf("%s",this_->code);
     printf("\n book name :");
     printf("%s",this_->book);
     printf("\n book writer name:");
     printf("%s",this_->writer);
     printf("\nnumber of this book :");
     printf("%s",this_->numb);
     printf("\n publish name :");
     printf("%s",this_->publish);
     //this_=this_->link;
     bool=1;
     break;
       }
       else
       {
       new_=this_;
       this_=this_->link;
       continue;
     }
   }
   if(!bool) printf("\t\trecord not found.\n" );
   else
     {
     printf("\t\tenter new data...\n");
     printf("\nenter book code:");
     gets(this_->code);
     printf("\nenter book name:");
     gets(this_->book);
     printf("\nenter book writer name:");
     gets(this_->writer);
     printf("\n enter number of this book:");
     gets(this_->numb);
     printf("\nenter publish name:");
     gets(this_->publish);
     printf("\n\n\n\r\t\tpress any key...\n");
     }
     }
     void searchbycode(void)
       {
       cher code[30];
       cher bool=0;
       new_=this_=first;
       printf("\n\tenter code:");
       gets(code);
       white(this_!=null)
  {
   if (!strcpy (this_->code,code))
     {
     printf("\nbook code:");
     printf("%s",this_->code);
     printf("\n book name:");
     printf("%s",this_->book);
     printf("\nbook write0r name:");
     printf("%s",this_->writer);
     printf("\nnumber of this book");
     printf("%s",this_->numb);
     printf("\npublish name:");
     printf("%s",this_->publish);
     printf("\n\n\n\r\t\tpress any key...");
     this_=this_->link;
     gtch();
     bool=1;
   }
   else
     {
     new_-this_;
     this_=this_->link;
     continue;
  }
       }
       if (!bool)
  {
    printf("\n\t\t record not found.\n");
    sleep(3);
    }
  }
  void  serchbyname(void)
  {
   char code[30];
   char bool=0;
   new_=this_=first;
   printf("\n\t enter book nameL:");
   gets(code);
   while (this_!=null)
      {
      if (!strcmp(this_->book,code))
        {
        printf("\nbook code:");
        printf("%s",this_->code);
        printf("\n book name:");
        printf("%s",this_->book);
        printf("\nbook writer name:");
        printf("%s",this_->writer);
        printf("\nnumber of this book");
        printf("%s",this_->numb);
        printf("\npublish name:");
        printf("%s",this_->publish);
        printf("\n\n\n\r\t\tpress any key...");
        this_=this_->link;
        gtch();
         bool=1;
         }
         else
     {
     new_-this_;
     this_=this_->link;
     continue;
  }
       }
       if (!bool)
  {
    printf("\n\t\t record not found.\n");
    sleep(3);
    }
  }
  void  serchbyname(void)
  {
   char code[30];
   char bool=0;
   new_=this_=first;
   printf("\n\t enter book nameL:");
   gets(code);
   while (this_!=null)
      {
      if (!strcmp(this_->book,code))
        {
        printf("\nbook code:");
        printf("%s",this_->code);
        printf("\n book name:");
        printf("%s",this_->book);
        printf("\nbook writer name:");
        printf("%s",this_->writer);
        printf("\nnumber of this book");
        printf("%s",this_->numb);
        printf("\npublish name:");
        printf("%s",this_->publish);
        printf("\n\n\n\r\t\tpress any key...");
        this_=this_->link;
        gtch();
         bool=1;
         }
         else
     {
     new_-this_;
     this_=this_->link;
     continue;
  }
       }
       if (!bool)
  {
    printf("\n\t\t record not found.\n");
    sleep(3);
    }
  }
  void  serchbyname(void)
  {
   char code[30];
   char bool=0;
   new_=this_=first;
   printf("\n\t enter book nameL:");
   gets(code);
   while (this_!=null)
      {
      if (!strcmp(this_->book,code))
        {
        printf("\nbook code:");
        printf("%s",this_->code);
        printf("\n book name:");
        printf("%s",this_->book);
        printf("\nbook writer name:");
        printf("%s",this_->writer);
        printf("\nnumber of this book");
        printf("%s",this_->numb);
        printf("\npublish name:");
        printf("%s",this_->publish);
        printf("\n\n\n\r\t\tpress any key...");
        this_=this_->link;
        gtch();
         bool=1;
         }
         else
     {
     new_-this_;
     this_=this_->link;
     continue;
  }
       }
       if (!bool)
  {
    printf("\n\t\t record not found.\n");
    sleep(3);
    }
  }
  void   main(void)
     {
     char ch;
     clrscr();
     frist=null;
     printf("\n\rloading in the file...");
      sleep(1);
      for(;;)
        {
        clrscr();
        printf ("\n\t\t\t 1-entry");
        printf ("\n\t\t\t 2-edit");
        printf ("\n\t\t\t 3-delete");
        printf ("\n\t\t\t 4-search by code");
        printf ("\n\t\t\t 5-search by name");
        printf ("\n\t\t\t 6-search by writer");
        printf ("\n\t\t\t 7-search by publish");
        printf ("\n\t\t\t 8-sort by code");
        printf ("\n\t\t\t 9-sort by name");
        printf ("\n\t\t\t a-sort by writer name");
        printf ("\n\t\t\t b-sort by publisher name");
        printf ("\n\t\t\t c-sort by name & writer");
        printf ("\n\t\t\t d-display");
        printf ("\n\t\t\t q-quit");
        ch=getch();
        sitch(tolower(ch))
         {
    case'1':
       enter();
       break;
    case'2':
        edit();
        break;
   case'3':
        delete_();
        break;
         case '4':
        searchbycode();
        break;
        case'5':
         searchbyname();
        break;
        case'6':
         searchbywriter();
        break;
        case'7':
         searchbypublish();
        break;
       case'8':
       sortbycode();
       break;
        case'9':
       sortbyname();
       break;
        case'a':
       sortbywriter();
       break;
        case'b':
       sortbypublish();
       break;
       case'c':
      sortbyname();
      sortbywriter();
      break;
      case'd':
      display();
      break;
      case'q':
      clrscr();
      printf("\n\rsaving in the file...");
      save();
      exit(0);
     }
  }
     }

تابع ماتریس واروون

#include
#include
#include
#include
main()
{
  clrscr();
  int i,j,u,k,n,T=0;
  int y[10],y1[10],z=0,zl=0,l=0,w=0,A[10],con=0,NT=1,n1;
  float c[10][10],b[10][10],a[10][10],B[10][10];
  float s[10][10],t[10][10],a1[10][10];
  printf("\t bode matrix ra vared konid:");
  scanf("%d",&n);
   printf("\n\t A[I][J]  : ");
  for(i=1;i<=n;i++)
   for(j=1;j<=n;j++) {
       gotoxy(3+5*(j-1),i+3);
       scanf("%f",&a[i-1][j-1]);
       a1[i-1][j-1]= a[i-1][j-1] ;
       if(i==j) b[i-1][j-1]=1;
       else b[i-1][j-1]=0;
       y1[i-1]=0; A[i-1]=i-1;
       y[i-1]=0;
      }
   n-=1;
      for(i=0;i<=n;i++)
      if(a[i][i]==0) con++;
      if(con>=n-1){
       while(NT){
for(i=0;i<=n;i++){
if(a[i][i]==0) {
   for(j=0;j<=n;j++)
   if(i<=n-1) {
        T=a[j][i];
        a[j][i]=a[j][i+1];
        a[j][i+1]= T;
        T=A[i];
        A[i]=A[i+1];
        A[i+1]=T;
  }
   else if(i==n){
   T=a[j][i];
   a[j][i]=a[j][0];
   a[j][0]= T;
   T=A[i];
   A[i]=A[0];
   A[0]=T;
   }
    }}
        con=0;
        for(i=0;i<=n;i++)
        if(a[i][i]==0) con++;
        if(con>=1)  continue;
        else NT=0;
       }
  goto loop1;
 }
   else
  while(z==0){  // start while
       loop1:
       for(i=0;i<=n;i++)
       for(j=0;j<=n;j++)
    s[i][j]=0;
   for(i=0;i<=n;i++)
    for(j=0;j<=n;j++){
       s[i][l]+=b[i][j]*a[j][l];
       if(i==j) t[i][j]=1;
        else t[i][j]=0;
        c[i][j]=0;
        }
    if((s[l][l]==0)&&(l  y[l]=1;
  y1[l]++;
  if(y1[l]==n+2){
   printf("****(DETERMINAN=0)****");
   getch();
   exit(0);
   }
  if(zl==0) {
       l++;
       continue;
      }
      else goto loop2;
  }
else if((s[l][l]==0)&&(l==n)){
        for(i=0;i<=n;i++)
        for(j=0;j<=n;j++){
     if(i==j) b[i][j]=1;
     else b[i][j]=0; }
       for(i=0;i<=n;i++)
       {
       y[i]=0;
       y1[i]++;
       if(y1[l]==n+2){
        printf("****NO****");
        getch();
        exit(0);
       }
       }
  if(T==0){    T=1;   continue; }
  else {
        if(w<=n-2) w++;
        else w=0;
        goto loop2;
       }
 }
   for(i=0;i<=n;i++){
      if(i==l) t[i][l]=1/s[i][l];
      else if(s[i][l]==0) t[i][l]=s[i][l];
      else t[i][l]=(s[i][l]/s[l][l])* -1;
      }
   for(i=0;i<=n;i++)
    for(j=0;j<=n;j++)
     for(k=0;k<=n;k++)
   c[j][i]+=t[j][k]*b[k][i];
   for(i=0;i<=n;i++){
       for (j=0;j<=n;j++)
       b[i][j]=c[i][j];
       s[i][j]=0;
      }
  printf("\n\n");
  loop2:
     if((l<=n)&&(zl!=1))    l++;
  if((l>n)||(zl==1)){
       zl=1;
       for(i=w;i<=n;i++)
       if(y[i]==1){
      y[i]=0;
      l=i;
      goto loop1;
     }
       z=1;
      }
  }//****Eof while
   for(i=0;i<=n;i++)
     for(j=0;j<=n;j++)
     if(A[i]==i)    B[i][j]=b[i][j];
     else {
      n1=A[i];
      B[n1][j]=b[i][j];
   }
  for(i=0;i<=n;i++)
   for(j=0;j<=n;j++){
       b[i][j]=B[i][j];
       c[i][j]=0;
      }
       printf("\n");
     for(i=0;i<=n;i++)
     for(j=0;j<=n;j++)
     for(k=0;k<=n;k++)
      c[i][j]+=a1[j][k]*b[k][i];
     printf("***  hasel zarbe matrix varoon dar khode matrix ** \n\n");
     for(i=0;i<=n;i++) {
    for(j=0;j<=n;j++)
    printf("%5.2f",c[i][j]);
    printf("\n");
         }
    printf(" \n*** varoon e matrix ***   \n\n");
    for(i=0;i<=n;i++)
    {
       for(j=0;j<=n;j++)
       printf("%5.2f", b[i][j] );
       printf("\n");
     }
getch();
}

برنامه تشخیص همبند یا ناهمبند بودن گراف و همیلتونی

#include
#include
#include
#include
main(){
int ras[50],deg[50],v[50][50];
int yy[50][50];
int a,sum,b,c,p,max;
int x,z,y,j,i,o,s;
int sam[50],dig[50];
int xx=0,zz=0,cc=0,vv=0;
int dog[50];

textcolor(11);
textbackground(5);
clrscr();

printf("\n\n                           IN THE NAME OF GOD");
printf("\n\n                      THE PROJ OF GRAPH WRITTEN BY:");
printf("\n\n                                          ");
printf("\n\n\n                       PRESS ANY KEY TO CONTINUE.");
getch();

textcolor(10);
textbackground(9);
clrscr();

printf("HOW MANY RAS :");
scanf("%d",&a);
printf("ENTER MATRIS :\n");
for(i=1;i<=a;i++){
for(j=1;j<=a;j++){
printf("V[%d][%d] : ",i,j);
scanf("%d",&v[i][j]);
yy[i][j]=v[i][j];
if(i==j)yy[i][j]=0;
if(i!=j)if(a!=2)if(yy[i][j]>0)yy[i][j]=1;
if(a==2)if(v[i][j]>2)yy[i][j]=2;}
printf("\n");}
textcolor(15);
textbackground(4);
clrscr();
/******************calculat****************************/
for(i=1;i<=a;i++){
sam[i]=0;
for(j=1;j<=a;j++){
sam[i]+=v[i][j];
if(i==j)sam[i]+=v[i][j];}
if((sam[i]%2)==0)xx+=1;else{ zz+=1;
if(sam[i]>2)vv+=1;}


}
/********************/
for(i=1;i<=a;i++){
dig[i]=0;
for(j=1;j<=a;j++){
dig[i]+=v[j][i];
if(i==j)dig[i]-=v[j][i];}
if(dig[i]==0)cc+=1;}
/********************/
for(i=1;i<=a;i++){
dog[i]=0;
for(j=1;j<=a;j++)
dog[i]+=yy[j][i];}

for(i=1;i<=a;i++)
for(j=1;j<=a;j++){
if(i!=j) if(yy[i][j]!=0) if(dog[j]>2) if(dog[i]>2)
{yy[i][j]-=1;yy[j][i]-=1;
dog[i]-=1;dog[j]-=1; }}
/*************************************************/
if(((zz)%2)!=0)printf("\n\n***********     INVALID GRAPH   *************\n");
else{
if(cc!=0){printf("\nGRAPH IS NOT HAMBAND & HAS NOT DOUR");}
else{if(a==0)printf("\n\n***********     INVALID GRAPH    *************\n");
else{
printf("\nGRAPH HAS EULERY MASIR\n");
if(xx!=a)printf("\nGRAPH HAS NOT EULERY DOUR\n");
else{

/************************* eulery dour ****************/
printf("\nEULERY DOUR IS : \n");
sum=0;i=1;j=1;
printf("V1");
GAIN:
for(b=1;b<=a;b++)
for(c=1;c<=a;c++)
sum+=v[b][c];
if(sum!=0){
if(i==j){
while(v[i][j]!=0){
printf(" V%d",j);
v[i][j]--;
}}
p=1;
for(x=1;x<=a;x++)
if(v[i][x]!=0){
ras[p]=x;
p++;}

for(y=1;y<=a;y++){
deg[y]=0;
for(z=1;z<=a;z++){
deg[y]+=v[y][z];
if(y==z)
deg[y]+=v[y][z];}}

max=0;
for(x=1;x<=(p-1);x++)
if((max)<=(deg[ras[x]]))
max=ras[x];
if(max==0)
goto main;
printf(" V%d",max);
v[i][max]--;
v[max][i]--;
j=max;i=max;
goto GAIN;

}
main:
}

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

if(vv!=0)printf("\n\nGRAPH HAS NOT HAMILTON DOUR\n");
else{if(vv!=zz)printf("\n\nGRAPH HAS NOT HAMILTON DOUR\n");
else{
/***************************************/
printf("\n\nHAMILTON DOUR IS :\n");
/************************* hamilton dour ****************/
sum=0;i=1;j=1;
printf("V1");
G:
for(b=1;b<=a;b++)
for(c=1;c<=a;c++)
sum+=yy[b][c];
if(sum!=0){
if(i==j){
while(yy[i][j]!=0){
printf(" V%d",j);
yy[i][j]--;
}}
p=1;
for(x=1;x<=a;x++)
if(yy[i][x]!=0){
ras[p]=x;
p++;}

for(y=1;y<=a;y++){
deg[y]=0;
for(z=1;z<=a;z++){
deg[y]+=yy[y][z];
if(y==z)
deg[y]+=yy[y][z];}}

max=0;
for(x=1;x<=(p-1);x++)
if((max)<=(deg[ras[x]]))
max=ras[x];
if(max==0)
goto maxi;
printf(" V%d",max);
yy[i][max]--;
yy[max][i]--;
j=max;i=max;
goto G;
}
maxi:
if(a>3)if((a%2)!=0)if(max!=1)printf(" V1");
}}}}}
getch();
}
/*************************************/

برنامه های درخواستی شما

تابع ماتریس واروون

برنامه تشخیص همبند یا ناهمبند بودن گراف و همیلتونی

برنامه معدل نمرات دانشجویان

محاسبه مقلوب یک عدد

دفترچه تلفن ساده

تابع تبدیل infix and postfix ساختمان داده ها

تابع دفترچه تلفن 118

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

بازی زیر دریایی

پیاده سازی توابع رشته ای strlen - strcopy -strcat

ضرب و جمع اعداد بزرگ

sort and search 

ضرب و جمع اعداد بزرگ

#include
#include
#include

char num1[100], num2[100];
int sum[101], mul[10001] ;
int flag,len1,len2,len,i,j, d, d1, d2, c, x, k, count;

int main()
{
 textmode(BW80);
 textcolor(15);
 textbackground(1);

 clrscr();
 printf("Enter first number: ");
 gets(num1);
 printf("Enter second number: ");
 gets(num2);

 len1=strlen(num1);
 len2=strlen(num2);


 if (len1>len2)
  len = len1;
 else
  len = len2;

/********************* C O M P A R E   N A M B E R S *****************/
 flag = 0 ;
 if (len1>len2){
  flag = 1;
 }
 if (len2>len2){
  flag = 1;
 }
 if (len1==len2){
  for(i=0 ; i   if (num1[i]>num2[i]){
    flag = 1;
    break;
   }
   if (num1[i]    flag = 1;
    break;
   }
  }
 }
 if (flag==0)
 printf("\n");

/*********************  S U M   N U M B E R S  **********************/
 c = 0 ;
 for(i=0 ; i    if (len1-i>0)
  d1 = num1[len1-i-1]-'0';
    else
  d1 = 0;
    if (len2-i>0)
  d2 = num2[len2-i-1]-'0';
    else
  d2 = 0;

    d  = (d1+d2+c) % 10 ;
    sum[i] = d ;
    c  = (d1+d2+c) / 10 ;
 }

 if (c>0){
  sum[i] = c;
  len++;
 }
 printf("\n=======================\n");
 printf("\nSum of these numbers is: ");
 for(i=len-1 ; i>-1 ; i--)
  printf("%d",sum[i]);

 printf("\n");
/**************** M U L T P L Y   N A M B E R S ********************/

 count=0;

 for(i=len1-1 ; i>-1 ; i--){
    d1 = num1[i]-'0';
    k = c = 0;
    for(j=len2-1 ; j>-1 ; j--){
     d2 = num2[j]-'0';
     d  = (d1*d2+c+mul[count+k]) % 10 ;
     c  = (d1*d2+c+mul[count+k]) / 10 ;
     mul[count+k] = d ;
     k++;
     len = count + k ;


    }   //  inner for
    if (c>0){
  mul[len] = c;
  x = 0;
    }
    else
  x = 1;
    count++;

 }      //  outer for
 printf("\n=======================\n");
 printf("\nMul of these numbers is: ");
 for(i=len-x ; i>-1 ; i--)
  printf("%d",mul[i]);
 getch();
 return 0;
}

sort and search

tag sort

shell sort

selection sort

quick sort

merge sort

bubble sort

insertionsort

tag sort

#include
#include
void tagsort(int tagarr[],int arrdata[],int size);
void change(int &x,int &y);
int main(){
const int maxsize=5;
int intarr[maxsize]={1,2,3,4,5};
int tagarr[maxsize];
tagsort(tagarr,intarr,maxsize);
cout<<"ORIGINAL"<<” “;
for(int k=0;kcout<cout<<"TAGGED:";
for(int i=0;icout<getch();
return 0;
}
///******************************************
void tagsort(int tagarr[],int arrdata[],int size)
{
int k,indexmin,pass;
for(k=0;ktagarr[k]=k;
for(pass=0;pass{ indexmin=pass;
for(k=pass+1;kif(arrdata[tagarr[k]]indexmin=k;
if(indexmin!=pass)
  change(tagarr[pass],tagarr[indexmin]);}//end of for
  }//end of tagsort
 //**********************************
  void change (int &x,int &y){
   int help;
   help=x;
   x=y;
   y=help;}//end of change

برنامه تقسیم و تفاضل

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

#define FALSE 0
#define TRUE  1

void main()
{
 double divided_sub(double[50],double[50],unsigned int,double);
   unsigned n,i;
   double x[50],y[50],answer,in;
   clrscr();  
   do {
   printf("Enter Number Of Parts (Max .50 ):\0");
   cin>>n;
   }while (n>50);
   for (i=0;i   {
   printf("Enter X%u:\0",i);
   cin>>x[i];
   printf("Enter Y%u:\0",i);
   cin>>y[i];
   }
   printf("\nEnter X To Caculate F(X):\0");
   cin>>in;
   answer=divided_sub(x,y,in);
   printf("\n F(%f)= %f\0",in,answer);
   getch();
   }
   /*********************************/
 double divided_sub(double a[50],double b[50],unsigned int n,double x)
   {
   unsigned int i,j,k,count=1;
   double c[51][50],p,l[50];
   for (i=0;i   for (j=0;j   {

   if (j<=i)
    c[j][i]=0;
    else
    if (i==0)
   c[j][i]=(b[j]-b[j-1])/(a[j]-a[j-a[j-(i+1)]);

   else

   c[j][i]=(c[j][i-1]-c[j-1][i-1])/(a[j]-a[j-a[j-(i+1)]);
   }


   for (i=0;i   l[i]=1;

   for (i=0;i   
   {


   for (j=0;j   l[i]*=(x-a[j]);
   ++count;
   
    }

p=b[0];
j=1;
i=0;

while(i{
p+=(c[j][i]*l[i]);
++i;
++j;
return (p);
}

8 وزیر

#include
#include
#define max 15
int kp[max];
int vr[max], dij1[2*max-1], dij2[2*max-1];
int rn;
void print (int n)
{
int i, j;
for (i=0; i{
for (j=0; jif (kp[j]==i)
printf("1 ");
else
printf("0 ");
printf("\n");
}
getch();
printf("\n\n\n");
}
void place(int n)
{
int i, j, k;
j=0;
kp[j]=0;
while (j>=0)
{
for (i=kp[j];i{
if (!vr[i] && !dij1[i+j] && !dij2[j-i+n-1])
{
if (j{
kp[j]=i;
vr[i]=1;
dij1[i+j]=1;
dij2[j-i+n-1]=1;
break;
}
else
{
kp[j]=i;
rn++;
print(n);
}
}
}
if (ikp[++j]=0;
else
{
if(--j>=0)
{
i=kp[j];
vr[i]=0;
dij1[i+j]=0;
dij2[j-i+n-1]=0;
kp[j]++;
}
}
}
}
void put (int n)
{
int i, j;
rn=0;
for (i=0; ivr[i]=dij1[i]=dij2[i]=0;
for (; i<2*n-1;i++)
dij1[i]=dij2[i]=0;
place(n);
}
void main()
{
int n;
clrscr();
printf("Type in the size of the chessboard, please!");
scanf("%d",&n);
put(n);
getch();
}

 

ضرب ماتریس ان در ان

#include
#include
#define N 4

void main (void)
{
unsigned int a[N][N],b[N][N],mul[N][N],i,j;

void mul_matrices(unsigned int [N][N],unsigned Int [N][N],unsigned int [N][N]);

clrscr();

printf("Getting A Matrix : \n\n\0");

for (i=0;ifor (j=0;j{
printf("A[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
printf("Getting B Matrix : \n\n\0");

for (i=0;ifor (j=0;j{
printf("B[%d][%d]=",i,j);
scanf("%d",&b[i][j]);
}
mul_matrices(a,b,mul);
printf("\n Members Of Mul Matrix : \n\n\0");

for (i=0;ifor (j=0;jprintf("ADD[%d][%d]=%d\n ",i,j,mul[i][j]);
}

void mul_matrices(unsigned int a[N][N],unsigned int b[N][N],unsigned int mul[N][N])
{
unsigned int i,j,k;

for (i=0;ifor (j=0;j{
mul[i][j]=0;

for (k=0;k

mul[i][j]+=a[i][k]*b[k][j];
}
}

معکوس کردن رشته

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
#define EOLN '\n'
/*read a line of text and write it out backwards, using recursion */
void main(){
void reverse(void);
cout<<" please enter a line of text belown "<<'\n';
reverse();
}
void reverse (void)
{
char c;
if ((c=getchar()) != EOLN) reverse();
putchar(c);
return;
}

انتگرال

 PROGRAM INTEGRAL;
 USES CRT;
 VAR X,S:REAL;
 FUNCTION FNX(X:REAL):REAL;
 BEGIN
 FNX:=X*X+3*X+4
 END;
 BEGIN
 CLRSCR;
 S:=0;
 X:=-5;
 WHILE X<5 DO
 BEGIN
 S:=S+0.001*FNX(X);
 X:=X+0.001
 END;
 GOTOXY(10,5);
 WRITELN(#159,'(X)=X',#253,'3X+4');
 GOTOXY(11,WHEREY+3);
 WRITELN('+5');
 WRITELN(#244:10);
 WRITELN(#179:10,#159,'(X)DX=',S:7:3);
 WRITELN(#245:10);
 WRITELN('-5':9);
 READLN;
 END.

تابع ایجاد نوار کپی


#include <conio.h>
#include <stdio.h>
int main(void)
{
   int k,z,i, j,p;

   clrscr();
   for (i=1; i<=5; i++)
   {
   p=6-i;
   printf("%d",p);
       for (j=2; j<=i; j++)

       cprintf("%d",i);
       k=i-1;
       for(z=1;z<=k;z++)
       printf("%d",i);
       cprintf("\n\n");
       textcolor(i+1);
       textbackground(i);
   }
   getch();
      return 0;
}

 

تابع فیبوناتچی

#include<stdio.h>
#include<conio.h>
int fibonanchi(int x);
int main()
{
int x,k;
printf("\n enter an intejer num:");
scanf("%d",&x);
for(k=1;k<=x+1;k+2)
printf("\n fibonanchi is:%d",fibonanchi(k));
getch();
return 0;
}
int fibonanchi(int k)
{
if(k==2)
return 1;
return(fibonanchi('x'-2)+fibonanchi('x'-1));
}

تقویم (فارس)

#include<conio.h>
#include<dos.h>
main(){
       int n,year,month,count_day,x,y3=1,y=1,y1=0,y2=4,day,k_year;
       char  *dd[7]={"ù“÷‹‹‹‹ª","ù“÷‹‹ªîþ","ù“÷‹‹ªø¢","ù“÷‹‹ªù¨",
       "ù“÷ª¤‘ú","ù“÷ªš÷• ","ùãõ‹‹‹‹›"} ;
       char  *mm[12]={"FAR","ORD","KHO","TIR","MOR","SHA",
        "MEH","ABA","AZA","DAI","BAH","ASF"};
       clrscr();textcolor(15); gotoxy(30,12);cprintf("ENTER YEAR   ");
       cscanf("%d",&year);
 clrscr();
       gotoxy(75,1);cprintf("%d",year);
      for(int block=1;block<=3;block++)
   {
    y3++;
    x=59;
    for(int week_day=0;week_day<7;week_day++)
   { if(week_day==6)textcolor(4); else textcolor(1);
   gotoxy(70,y3); cprintf("%s",dd[week_day]);  y3++; }
     for(month=y1;month<y2;month++)
        { textcolor(3);gotoxy(x,y);cprintf("%s",mm[month]);x-=18;}
     y+=8;  y1+=4;  y2+=4;
   }
       y=year-1303;
       if((y+1)%4)  k_year=1;else k_year=0;
       y=(y+(y/4))%7;
       if(!y) y=7;
       y++;
       if(year==1379) y--;
       if(year==1378) k_year=1;
       x=65;
       for(month=1;month<=12;month++){
     if(month==5||month==9)  { x=65;  y+=8;}
     if(month<=4){y1=2;y2=8;}
     else if(month>=5 && month<=8){ y1=10;y2=16; }
     else  {y1=18; y2=24;}
     if( month<=6) day=31;
     else if(month>=7&&month<=11) day=30;
     else if(month==12&&k_year)  day=29;
     else if(month==12&&!k_year) day=30;
     count_day=1;
     //textcolor(2);
     while(day>=count_day){
          while(y<=y2){
       delay(20);
       if(y==8||y==16||y==24)textcolor(4);
       else textcolor(2);
       gotoxy(x,y);cprintf("%d",count_day);
       y++; count_day++;
       if(count_day>day)break;
         }
          x-=3;
          if(count_day>29) y3=y;
          y=y1;
         }
   y=y3;
   }
   getch(); getch();
 textcolor(15);gotoxy(25,12);cprintf("WRITEN BY:: JALIL MOHAMMADI");
       }

محاسبه سینوس تابع

 #include<math.h>         //y=10sin(x/5);
 #include <stdio.h>
 #include <conio.h>
void main()
{
double a=-40.00;
unsigned char b;
clrscr();
textcolor(9);
gotoxy(1,12);
for(b=1;b<=80;b++)
cprintf("-\0");
for(b=1;b<=25;b++)
{
gotoxy(40,b);
cprintf("|\0");
}
gotoxy(1,1);
textcolor(12);
do{
gotoxy(40+(int)a,(int)(12+10*sin(a/5)));
cprintf("Û\0");
a+=0.1;
}while(a<=40);
}

شطرنج

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<BIOS.H >
void copy(int s1, int s2, int z1 ,int z2 ,int x,int y);
 unsigned char read_point(int x,int y ) ;
unsigned char mempoint(int x,int y ,int color);
int main(void)
{
   union k{
    char c[2];
    int i,j;
    }key;
   char p[2]={40,80},ch;
   int array[9][9];
   int i,j;
   int a,b,x,y;
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;
   initgraph(&gdriver, &gmode, "");
   errorcode = graphresult();
   setcolor(2);
   settextstyle(1,0,2);
   outtextxy(25,420," F1..       F2..       A..       B..      ");
   setviewport(150,50,500,400,1);
   setfillpattern(p,7);
   setfillstyle(1,7);
   for(i=0;i<10 ;i++)
   for(j=0;j<10 ;j++)
  array[i][j]=0;
   floodfill(260,160,3);
   for(i=0;i<325 ;i+=35)
   for(j=0;j<325 ;j+=35)
         rectangle(j,i,35+j,35+i);
  setviewport(460,365,495,395,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,1);
  array[0][0]=-1;
  setviewport(145,50,180,80,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,4);
 array[9][9]=-1;
  a=0 ;b=0; x=0;y=0;
 do{
     ch=getch();
     key.i=bioskey(0);
      if(!key.c[0])
   switch (key.c[1])
    {
   case 72:
     if(ch=='a')
     if(b<=280){
     setviewport(460-a,365-b,495-a,395-b,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,57);
     if(getpixel(j+a,i+b)==7)
     b-=35;
     else b+=35;
     setviewport(460-a,365-b,495-a,395-b,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,1);   //}
          }
      if(ch=='b')
     if(y<= 280){
     setviewport(145-x,50-y,180-x,80-y,1);
        for(i=0;i<200;i++)
        for(j=0;j<200;j++)
        putpixel(10+j,5+i ,54);
     y+=35;
     setviewport(145-x,50-y,180-x,80-y,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,4);   }
     break;
  case 75:
      if(ch=='a')
      if(a<=280){
      setviewport(460-a,365-b,495-a,395-b,1);
      for(i=0;i<200;i++)
      for(j=0;j<200;j++)
      putpixel(10+j,5+i ,57);
      if(getpixel(j+a,i+b)==7)
      a-=35;
      else a+=35;
      setviewport(460-a,365-b,495-a,395-b,1);
      for(i=0;i<200;i++)
      for(j=0;j<200;j++)
      putpixel(10+j,5+i ,1);
          }
      if(ch=='b')
     if(x<= 280){
     setviewport(145-x,50-y,180-x,80-y,1);
        for(i=0;i<200;i++)
        for(j=0;j<200;j++)
        putpixel(10+j,5+i ,54);
     x+=35;
     setviewport(145-x,50-y,180-x,80-y,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,4);   }
      break;
  case 77:
      if(ch=='a')
      if(a>=35){
      setviewport(460-a,365-b,495-a,395-b,1);
      for(i=0;i<200;i++)
      for(j=0;j<200;j++)
      putpixel(10+j,5+i ,57);
      if(getpixel(j+a,i+b)==7)
      a+=35;
      else a-=35;
      setviewport(460-a,365-b,495-a,395-b,1);
      for(i=0;i<200;i++)
      for(j=0;j<200;j++)
      putpixel(10+j,5+i ,1);
          }
      if(ch=='b')
     if(x>= -280){
     setviewport(145-x,50-y,180-x,80-y,1);
        for(i=0;i<200;i++)
        for(j=0;j<200;j++)
        putpixel(10+j,5+i ,54);
     x-=35;
     setviewport(145-x,50-y,180-x,80-y,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,4);   }
      break;

   case 80:
   if(ch=='a')
   if(b>=35){
     setviewport(460-a,365-b,495-a,395-b,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,57);
     if(getpixel(j+a,i+b)==7)
     b+=35;
     else b-=35;
     setviewport(460-a,365-b,495-a,395-b,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,1);
          }
     /*********************************/
     if(ch=='b')
     if(y>= -280){
     setviewport(145-x,50-y,180-x,80-y,1);
        for(i=0;i<200;i++)
        for(j=0;j<200;j++)
        putpixel(10+j,5+i ,54);
     y-=35;
     setviewport(145-x,50-y,180-x,80-y,1);
     for(i=0;i<200;i++)
     for(j=0;j<200;j++)
     putpixel(10+j,5+i ,4);   }
     break;
    }
      } while(key.c[0]!='q');
   closegraph();
   return 0;
}

 

برج هانوی

#include
#include
#include
#include
#include
#include
#include
#include
#include

#define towers_col 14
#define towers_place 19
#define tower "ÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄ"

class DISKS
      {
 public:
 DISKS(int dnum);
 int xpos,ypos;
 int color;
 char *fig;
 void move(int num,int from,int to);
      }**disk;

int towersx[3]={15,42,68};
int towersy[3]= {towers_place-1,towers_place-1,towers_place-1};
int k,all;
char beep,**buf;
char far *Video_Mem;

void write_string(int x, int y, char *p, int attrib)
{
 register int i;
 char far *v;

 v= Video_Mem;
 v+= ((y-1) * 160) + (x-1)*2;
 for (;*p;i++)
 {
  *v++= *p++;
  *v++= attrib;
 }
}
/******************************************************************************/

void cursor_size(int a,int b)
{
 union REGS reg;

 reg.h.ah = 1;
 reg.h.bh = 0;
 reg.h.ch = a;
 reg.h.cl = b;
 int86(0x10,®,®);
}
/******************************************************************************/

void video_mode(void)
{
 union REGS r;

 r.h.ah= 15;
 if ((int86(0x10,&r,&r) & 255) == 7)
     Video_Mem= (char far *)0xB0000000;
 else
     Video_Mem= (char far *)0xB8000000;

}
/******************************************************************************/

DISKS::DISKS(int dnum)
     {
 fig= (char *)malloc(2*dnum+2);
 memset(fig,'ß',2*dnum +1);
 *(fig)= 'Û';
 *(fig + 2*dnum )='Û';
 *(fig + 2*dnum +1)= 0;
 color= 16 - dnum;
 xpos=towersx[0] -(dnum+1);
 ypos=towersy[0];
 buf[dnum- 1]= (char *)malloc(100);
 gettext(xpos,ypos,xpos+strlen(fig)- 1,ypos,buf[dnum- 1]);
 write_string(xpos,ypos,fig,color);
 towersy[0]-= 1;
     }
/******************************************************************************/

void DISKS::move(int num,int from,int to)
     {
     char buffer[100];
     static n= 1,speed =120;
     char ch= 0;

     strcpy(buffer,buf[num- 1]);
     gotoxy(12,23);
     textattr(15);
     cprintf("%d Of %d  ÄÄÄ>   ",n++,all);
     cprintf("Moving Disk #%d",num);
     cprintf(" From Tower %c",'A'+from);
     cprintf(" To Tower %c .   ",'A'+to);
     do
     {
 puttext(xpos,ypos,xpos+strlen(fig)- 1,ypos,buffer);
 if ((ypos > towers_place -k-3)&&(xpos==towersx[from]-(num+1)))
    ypos--;
 else
 {
    if (xpos != towersx[to] -(num+1))
    {
       if (xpos < towersx[to] -(num+1))
   xpos++;
       if (xpos > towersx[to] -(num+1))
   xpos--;
    }
    else
       if (ypos < towersy[to])
   ypos++;
 }
 gettext(xpos,ypos,xpos+strlen(fig)- 1,ypos,buffer);
 write_string(xpos,ypos,fig,color);
 delay(speed/6);
 if (kbhit())
    ch= getch();
 switch (ch)
 {
        case '+':
         if (speed > 6)
      speed--;
         ch= 0;
         break;
        case '-':
         if (speed < 180)
      speed++;
         ch= 0;
         break;
 }
     *(int *)0x0000041c=*(int *)0x0000041a;
     }
     while ((xpos!=towersx[to] -(num+1)) || (ypos!=towersy[to]));
     if (toupper(ch) == 'S')
 beep = !beep;
     if (beep)
     { sound((k-num+1)*30+800);
 delay(speed/3);
 nosound();
     }
     switch (ch)
     {
     case 27:
     textattr(11);
     getch();
     clrscr();
     cursor_size(3,4);
     exit(0);
     case 32:
     while(((ch=getch()) != 32) && (ch != '+') && (ch != '-') && (ch != 27));
     break;
     }
     ch= 0;
     towersy[from]+=1;
     towersy[to]-=1;
     strcpy(buf[num- 1],buffer);
     }
/******************************************************************************/

void costruct(int num)
     {
 int i;

 textattr(8);
 clrscr();
 for (i=0;i<=97;i++)
     cputs(" Towers Of Hanoi  ");
 textattr(9);
 cputs("\r  \n\rÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
 textattr(3);
 cputs("   Spacebar:Pause            +,-:Speed            S:Sound            Esc:Exit");
 disk= (DISKS **)malloc(num*sizeof(*disk));
 for (i= 0;i < num;i++)
     disk[i]= (DISKS *)malloc(sizeof(**disk));
 buf= (char **)malloc(num*sizeof(*buf));
 write_string(towersx[0]-10,towers_place,tower,towers_col);
 write_string(towersx[1]-10,towers_place,tower,towers_col);
 write_string(towersx[2]-10,towers_place,tower,towers_col);
 for (i= 1;i< num+2;i++)
 {
     write_string(towersx[0]-1,towers_place-i,"³",towers_col);
     write_string(towersx[1]-1,towers_place-i,"³",towers_col);
     write_string(towersx[2]-1,towers_place-i,"³",towers_col);
 }
 write_string(towersx[0]-1,towers_place+1,"A",towers_col);
 write_string(towersx[1]-1,towers_place+1,"B",towers_col);
 write_string(towersx[2]-1,towers_place+1,"C",towers_col);
 for (i= num;i> 0;i--)
     disk[i]= new DISKS(i);
     }

/******************************************************************************/
void swap(int &a,int &b){

   int c;
   c=a;
   a=b;
   b=c;
   }
// ************************************************************************

void Hanoi(int n,int from,int temp,int to)
{
  if (n>1){
    Hanoi(n-1,from,to,temp);
    }
  if(n>0)
    disk[n]->move(n,from,to);
  if(n>0)  {
    Hanoi(n-1,temp,from,to);

    }
}
/******************************************************************************/

void intro(void)
{
 char s[3];
 char ch;

 cursor_size(1,0);
 textattr(11);
 clrscr();
 gotoxy(34,1);
 cputs("IN THE OF GOD");
 gotoxy(29,2);
 cputs("  WELL COM TO TOWERS OF\n\n\n\n\r");
 textattr(9);
 cputs("        Û        Û        ÛÛ       ÛÛ          Û      ÛÛÛÛÛÛ    ÛÛÛÛÛ \n\r");
 cputs("        Û        Û       Û  Û      Û Û         Û     Û      Û     Û   \n\r");
 cputs("        Û        Û      Û    Û     Û  Û        Û    Û        Û    Û   \n\r");
 cputs("        Û        Û     Û      Û    Û   Û       Û    Û        Û    Û   \n\r");
 cputs("        Û        Û    Û        Û   Û    Û      Û    Û        Û    Û   \n\r");
 cputs("        ÛÜÜÜÜÜÜÜÜÛ    ÛÜÜÜÜÜÜÜÜÛ   Û     Û     Û    Û        Û    Û   \n\r");
 cputs("        Û        Û    Û        Û   Û      Û    Û    Û        Û    Û   \n\r");
 cputs("        Û        Û    Û        Û   Û       Û   Û    Û        Û    Û   \n\r");
 cputs("        Û        Û    Û        Û   Û        Û  Û    Û        Û    Û   \n\r");
 cputs("        Û        Û    Û        Û   Û         Û Û     Û      Û     Û   \n\r");
 cputs("        Û        Û    Û        Û   Û          ÛÛ      ÛÛÛÛÛÛ    ÛÛÛÛÛ \n\n\n\r");
 textattr(15);
 cputs("                      Wrietn By   HOSAIN YOUSEFPOUR .\n\n\r");
 textattr(14);
 cputs("        Enter The Number Of Disks (1..13): <    >");
 s[0]= 3;
 while (!((k < 14)&&(k > 0)))
 {
       gotoxy(46,21);
       cputs("..\b\b");
       textattr(12);
       cgets(s);
       textattr(14);
       k= atoi(s+2);
 }
 cputs("\n\n\r        With Sound ?(Y/N)");
 all= pow(2,k)-1;
 while (((ch= toupper(getch())) != 'N') && (ch != 'Y') && (ch != 27));
 if (ch == 27)
 {
    textattr(11);
    clrscr();
    cursor_size(3,4);
    exit(0);
 }
 beep= ch- 'N';
}
/******************************************************************************/

void main (void)
     {

     intro();
     video_mode();
     costruct(k);
     Hanoi(k,0,2,1);
     while(getch() != 27);
     textattr(11);
     clrscr();
     cursor_size(3,4);
     exit(0);
     }

برنامه تایمر


       //             ***** program watch of digital *****
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<process.h>
 main()
  {
  int d,c,b,e;
  textmode(C40);
  textattr(0x2c);
   for(d=0;d<=59;d++)
   for(c=0;c<=59;c++)
   for(b=0;b<=59;b++)

    {
      if(b<59)
      clrscr();
      window(15,13,25,14);
      textbackground(0);clrscr();
      window(14,12,24,13);
      textbackground(17);clrscr();
      gotoxy(15,12 );
      cout<<d<<":"<<c<<":"<<b;
      delay(1000);
      while(b==30)  exit(0);
    }
   getch();
 }

تابع اعداد تام و اول

#include <stdio.h>
#include <math.h>
#include <iostream.h>
#include <conio.h>
#include<complex.h>
int main(void)
{

   int i,j,n,r,m,s,p=0,t=0;
   clrscr();
   cin>>n;
   for (i=2;i<=n;i++)
   {
   s=1;
   m=sqrt(i);
   if(i==m*m)
   {
   s+=m;
   m-=1;
   }
   for(j=2;j<=m;j++)
   {
   if(i/j==floor(i/j))s=s+j+i/j;
   if (s==i)
   {
   cout<<"is tam";
   t+=1;
   }
   if(s==1){
   cout<<"is prime";
   p+=1;
    }
   }
    }
   cout<<p,t;
   getch();

    return(0);
    }

تابع اعداد اول

/*#include <stdio.h>
#include <math.h>
#include <iostream.h>
#include <conio.h>

int main(void)
{
   int n,i,p,k,x,s,f;
   clrscr();
   cout<<"enter n:";
   cin>>n;
   if (n==1)printf("\n","is not avval");
   for (p=2;p<=n;p++)
   {
   s-=s;
   for(i=1;i<=(p/2);i++)
   {
   k=p%i;
   if(k==0)s++;
      }
      if(s==1)printf("%d\n",i);
   }
   getche();

    }

تابع ایجاد صدا یا موزیک

 #include<stdio.h>
 #include<graphics.h>
 #include<conio.h>
 #include<string.h>
 #include<process.h>
 #include<dos.h>
void main(){
 textcolor(14);
 textbackground(1);
 clrscr();
 cprintf("\n ."); delay(150); sound(130); delay(1); nosound();
 cprintf(".");delay(150);sound(1300); delay(1); nosound();
 cprintf("¢");delay(150);sound(1200); delay(1); nosound();
 cprintf("þ");delay(150);sound(1200); delay(1); nosound();
 cprintf("ø");delay(150);sound(140); delay(1); nosound();
 cprintf("ª");delay(150);sound(196); delay(1); nosound();
 cprintf(" š");delay(150);sound(157); delay(1); nosound();
 cprintf("¤");delay(150);sound(1150); delay(1); nosound();
 cprintf("‘");delay(150);sound(1130); delay(1); nosound();
 cprintf("¡");delay(150);sound(180); delay(1); nosound();
 cprintf("‘");delay(150);sound(0); delay(1); nosound();
 cprintf("—");delay(150);sound(1110); delay(1); nosound();
 cprintf(" ¢");delay(150);sound(1155); delay(1); nosound();
 cprintf("þ");delay(150);sound(1110);delay(1);nosound();
 cprintf("û");delay(150);sound(1140);delay(1);nosound();
 cprintf("¢");delay(150);sound(1139);delay(1);nosound();
 cprintf("¤");delay(150);sound(1100);delay(1);nosound();
 cprintf("‘");delay(150);sound(1150);delay(1);nosound();
 cprintf("ª");delay(150);sound(119);delay(1);nosound();
 cprintf("ê");delay(150);sound(190);delay(1);nosound();
 cprintf(" ");delay(150);sound(1);delay(1);nosound();
 cprintf("¤");delay(150);sound(111);delay(1);nosound();
 cprintf(" ü");delay(150);sound(190);delay(1);nosound();
 cprintf("¢");delay(150);sound(134);delay(1);nosound();
 cprintf("þ");delay(150);sound(1130);delay(1);nosound();
 cprintf("ó");delay(150);sound(140);delay(1);nosound();
 cprintf("î");delay(150);sound(180);delay(1);nosound();
 cprintf(" ");delay(150);sound(120);delay(1);nosound();
 cprintf("‘");delay(150);sound(130);delay(1);nosound();
 cprintf("‹");delay(150);sound(130);delay(1);nosound();
 cprintf("ê");delay(150);sound(1130);delay(1);nosound();
 cprintf("¯");delay(150);sound(130);delay(1);nosound();
 cprintf("ó ");delay(150);sound(1130);delay(1);nosound();

 cprintf("\n\n‘ó"); delay(150); sound(30); delay(1); nosound();
 cprintf("‘");delay(150);sound(1300); delay(1); nosound();
 cprintf("Ÿ");delay(150);sound(1200); delay(1); nosound();
 cprintf(" ");delay(150);sound(0); delay(1); nosound();
 cprintf("ö");delay(150);sound(140); delay(1); nosound();
 cprintf("þ");delay(150);sound(196); delay(1); nosound();
 cprintf("õ");delay(150);sound(157); delay(1); nosound();
 cprintf("û");delay(150);sound(1150); delay(1); nosound();
 cprintf(" ");delay(150);sound(0); delay(1); nosound();
 cprintf("ö");delay(150);sound(180); delay(1); nosound();
 cprintf("ø");delay(150);sound(1110); delay(1); nosound();
 cprintf("¤");delay(150);sound(1110); delay(1); nosound();
 cprintf("þ");delay(150);sound(1155); delay(1); nosound();
 cprintf("“");delay(150);sound(1110);delay(1);nosound();
 cprintf(" ");delay(150);sound(0);delay(1);nosound();
 cprintf("ø");delay(150);sound(1139);delay(1);nosound();
 cprintf("¤");delay(150);sound(1100);delay(1);nosound();
 cprintf("“");delay(150);sound(1150);delay(1);nosound();
 cprintf(" ");delay(150);sound(119);delay(1);nosound();
 cprintf("©");delay(150);sound(190);delay(1);nosound();
 cprintf("‘");delay(150);sound(1);delay(1);nosound();
 cprintf("“");delay(150);sound(111);delay(1);nosound();
 cprintf("÷");delay(150);sound(190);delay(1);nosound();
 cprintf(" ");delay(150);sound(0);delay(1);nosound();
 cprintf("‘");delay(150);sound(1130);delay(1);nosound();
 cprintf("›");delay(150);sound(140);delay(1);nosound();
 cprintf("÷");delay(150);sound(180);delay(1);nosound();
 cprintf("þ ");delay(150);sound(120);delay(1);nosound();
 cprintf("");delay(150);sound(130);delay(1);nosound();
 cprintf(" ");delay(150);sound(130);delay(1);nosound();
 cprintf("¢");delay(150);sound(130);delay(1);nosound();
 cprintf("þ");delay(150);sound(1130);delay(1);nosound();
 cprintf("ã");delay(150);sound(130);delay(1);nosound();
 cprintf("¨ ");delay(150);sound(1130);delay(1);nosound();

getch();
}

تابع حل معادله درجه 2

#include<stdio.h>
#include<conio.h>
#include<math.h>
main(){
float delta,a,b,c;
float x,x1,x2,z;
printf("enter a:");
scanf("%f",&a);
printf("enter b:");
scanf("%f",&b);
printf("enter c:");
scanf("%f",&c);
delta=(b*b)-((4)*(a)*(c));
if(delta<0)printf("delta < 0");
if(delta==0){
x=(-b)/(2*a);
printf("X = %3.2f",x);}
if(delta>0){z=sqrt(delta);
x1=(-b-z)/(2*a);
x2=(-b+z)/(2*a);
printf("x1 = %3.2f",x1);
printf("\nx2 = %3.2f",x2);}
printf("\n");
getch();
}

 

تابع ساختن فولدر در درایو

 

 #include <string.h>
 #include <stdio.h>
 #include <dir.h>

 int main(void)
 {
    char s[MAXPATH];
    char drive[MAXDRIVE];
    char dir[MAXDIR];
    char file[MAXFILE];
    char ext[MAXEXT];

    getcwd(s,MAXPATH);              /* get the current working directory */
    strcat(s,"\\");                 /* append on a trailing character */
    fnsplit(s,drive,dir,file,ext);  /* split the string to separate elems */
    strcpy(file,"DATA");
    strcpy(ext,".TXT");
    fnmerge(s,drive,dir,file,ext);   /* merge everything into one string */
    puts(s);                         /* display resulting string */

    return 0;
}

پیدا کردن ماکزیمم در ماتریس


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

     int main(void)
      {
      int mat[5][5],i,j,
      c[5],d[5],
      max[5]={0,0,0,0,0},min[5]={0,0,0,0,0};
   /****************************************************/
      textcolor(15);
      clrscr();
      printf("Please enter the matrix:");
      for (i=0;i<5;i++)
      {
      for (j=0;j<5;j++)
      {
      printf("mat[%d][%d]:",i,j);
      scanf("%d",&mat[i][j]);
      if(mat[i][j]>max[i]){max[i]=mat[i][j];c[i]=j;}
      }
      printf("now max is :%d\n in % d ",max[i],c[i]);
      }
      printf("\n");
      getch();
   /***********************************************************/
     textcolor(11);
     clrscr();
     for (i=0;i<5;i++)
     {
     for (j=0;j<5;j++)
     {
     printf("%5d",mat[i][j]);
     }
     printf("\n");
     }
     printf("\n");
     for (i=0;i<5;i++)
     {
     printf(" max[%d]:%d ",i,max[i]);
     }
     getch();
   /******************************************************/
   for(i=1;i<5;i++)
   {
   if(c[i]==d[i]){printf("%d %d in %d %d ", mat[c[i],d[i]]),c[i],d[i]);
   }
   /******************************************************/
   return 0;
   }

تعریف کلیدهای صفحه کلید برای طراحی منوها

 #include<dos.h>
 #include<graphics.h>
 #include<stdlib.h>
 #include <stdio.h>
 #include <conio.h>
 #define CLEAR "\x1B[2J"
 #define GOLEFT "\x1B[D"
 #define GORIGHT "\x1B[C"
 #define GOUP "\x1B[A"
 #define GODOWN "\x1B[B"
 #define TOPSCREEN "\x1B[1;1f"
 #define ENDSCREEN "\x1B[25;80f"
 #define DRAW *(farptr+(wherey()-1)*80+wherex()-1)
 char leftup =218,horizental=196,rightup=191,
 leftdown=192  , rightdown =217 ,downup =193 ,updown=194,
 leftright=195 , rightleft=180  , central=197,vertical =179;
 int attribute=0x0700;
 FILE *fp;
 void main()
  {
/*******************************************************/
  void setline(void);
  void setblink(void);
  void setintensity(void);
  void setforeground(int);
  void setbackground(int);
  void clearscreen(void);
  void savescreen(char[]);
  void loadscreen(char[]);
  void helpuser(void);
/*********************************************/
  unsigned c1,c2;
  int far *farptr;
  farptr= (int far *)0xb8000000;
  printf(CLEAR);
  while ((c1=getch())!=3)
  {
  if(c1==0)
  {
  c2=getch();
  switch(c2)
  {
  case 68:setline();               //setline style
  break;                           // F10
  case 133:setblink();     //set blink
  break;                           //F11
  case 134:setintensity();         //setintensity
  break;      //F12
 /*******************************************************/
  case 104:                        /*    ALT,F1   */
  case 105:                        /*    ALT,F2   */
  case 106:                        /*    ALT,F3   */
  case 107:                        /*    ALT,F4   */
  case 108:                        /*    ALT,F5   */
  case 109:                        /*    ALT,F6   */
  case 110:                        /*    ALT,F7   */
  case 111:                        /*    ALT,F8   */
  setforeground(c2);
  break;  //setforeground color
 /*******************************************************/
  case 94:                        /*    CRL,F1   */
  case 95:                        /*    CRL,F2   */
  case 96:                        /*    CRL,F3   */
  case 97:                        /*    CRL,F4   */
  case 98:                        /*    CRL,F5   */
  case 99:                        /*    CRL,F6   */
  case 100:                       /*    CRL,F7   */
  case 101:                       /*    CRL,F8   */
  setbackground(c2);
  break;       //setbackground color
 /*******************************************************/
  case 67:clearscreen();break;    //clearscreen
  case 71:gotoxy(1,wherey());break;     //HOME
  case 79:gotoxy(80,wherey());break;    //END
  case 73:gotoxy(wherex(),1);break;     //page up
  case 81:gotoxy(wherex(),25);break;    //page down
  case 119:printf(TOPSCREEN);break;     //CRL+HOME
  case 117:printf(ENDSCREEN);break;     //CRL+END
  case 75:printf(GOLEFT);break;         //LEFT ARR
  case 77:printf(GORIGHT);break;        //RIGHT ARR
  case 72:printf(GOUP);break;           //UP ARR
  case 80:printf(GODOWN);break;         //DOWN ARR
  case 155:printf(GOLEFT);DRAW=horizental|attribute;
  break;                                //ALT,LEFT ARR
  case 157:printf(GORIGHT);DRAW=horizental|attribute;
  break;                                //ALT,RIGHT ARR
  case 152:DRAW=vertical|attribute;printf(GOUP);
  break;                                //ALT,UP ARR
  case 160:DRAW=vertical|attribute;printf(GODOWN);
  break;                                //ALT,DOWN ARR
/*************************************************/
  case 63:DRAW=leftup|attribute;
  break;                //F5
  case 64:DRAW=rightup|attribute;
  break;                //F6
  case 65:DRAW=rightdown|attribute;
  break;                //F7
  case 66:DRAW=leftdown|attribute;
  break;                //F8
  case 22:DRAW=updown|attribute;
  break;                //ALT +U
  case 32:DRAW=downup|attribute;
  break;                //ALT +D
  case 38:DRAW=leftright|attribute;
  break;                //ALT+L
  case 19:DRAW=rightleft|attribute;
  break;                //ALT+R
  case 46:DRAW=central|attribute;
  break;                //ALT+C
  case 83:delline();
  break;                //ERASE LEFT CURSOR
  case 82:insline();
  break;                                //INSERT
/***********************************************/
  case 60:savescreen("screen.txt");
  break;        // F2  save screen
  case 61:loadscreen("screen.txt");
  break;        // F3  load screen
  case 62:savescreen("screen.txt");
  printf(CLEAR);
  exit(1);
  //break;        // F4  save and exit
  case 59:helpuser();                   //F1
  break;
  }
  }
  else
  {
  switch(c1)
  {
/*************************************************/
 case 27:printf(CLEAR);continue;       //ESC
 case 8:printf(GOLEFT);DRAW=0x20|attribute;break; //back space
 case 13:gotoxy(1,wherey()+1);break;   //enter
 default:
 {
 *(farptr+(wherey()-1)*80+wherex()-1)=c1|attribute;
 printf(GORIGHT);
 }
   }
    }
     }
      }
/***********************************************/
void setline(void)
{
switch(horizental)
{
case 196:
leftup=201;
horizental=205;
rightup=187;
leftdown=200;
rightdown=188;
downup=202;
updown=203;
leftright=204;
rightleft=185;
central=206;
vertical=186;
break;
/****************************************************
 *                                                                       *
 *                                                                       *
 ***********************************************/
case 205:
leftup=176;
horizental=176;
rightup=176;
leftdown=176;
rightdown=176;
downup=176;
updown=176;
leftright=176;
rightleft=176;
central=176;
vertical=176;
break;
/*********************************************/
case 176:
leftup=177;
horizental=177;
rightup=177;
leftdown=177;
rightdown=177;
downup=177;
updown=177;
leftright=177;
rightleft=177;
central=177;
vertical=177;
break;
/***********************************************/
case 177:
 leftup=178;
 horizental=178;
 rightup=178;
 leftdown=178;
 rightdown=178;
 downup=178;
 updown=178;
 leftright=178;
 rightleft=178;
 central=178;
 vertical=178;
 break;
/*************************************************/
case 178:
leftup=219;
horizental=219;
rightup=219;
leftdown=219;
rightdown=219;
downup=219;
updown=219;
leftright=219;
rightleft=219;
central=219;
vertical=219;
break;
/**************************************************/
case 219:
leftup=220;
horizental=220;
rightup=220;
leftdown=220;
rightdown=220;
downup=220;
updown=220;
leftright=220;
rightleft=220;
central=220;
vertical=220;
break;


/*******************************************/
case 220:
leftup=221;
horizental=221;
rightup=221;
leftdown=221;
rightdown=221;
downup=221;
updown=221;
leftright=221;
rightleft=221;
central=221;
vertical=221;
break;

/********************************************/
case 221:
leftup=222;
horizental=222;
rightup=222;
leftdown=222;
rightdown=222;
downup=222;
updown=222;
leftright=222;
rightleft=222;
central=222;
vertical=222;
break;

/*********************************************/
case 222:
leftup=223;
horizental=223;
rightup=223;
leftdown=223;
rightdown=223;
downup=223;
updown=223;
leftright=223;
rightleft=223;
central=223;
vertical=223;
break;

/**********************************************/
case 223:
leftup=254;
horizental=254;
rightup=254;
leftdown=254;
rightdown=254;
downup=254;
updown=254;
leftright=254;
rightleft=254;
central=254;
vertical=254;
break;
/**********************************************/
case 254:
leftup=218;
horizental=196;
rightup=191;
leftdown=192;
rightdown=217;
downup=193;
updown=194;
leftright=195;
rightleft=180;
central=197;
vertical=179;
break;
}
}
/*---------------------------------------------------------------------*/
void setblink(void)
{
attribute=attribute^0x8000;
}
void setintensity(void)
{
attribute=attribute^0x800;
}
void setforground(char x)
{
switch(x)
{
case 104:attribute=attribute &0xf800;break;
case 105:attribute=attribute &0xf800;attribute=attribute|0x0100;break;
case 106:attribute=attribute &0xf800;attribute=attribute|0x0200;break;
case 107:attribute=attribute &0xf800;attribute=attribute|0x0300;break;
case 108:attribute=attribute &0xf800;attribute=attribute|0x0400;break;
case 109:attribute=attribute &0xf800;attribute=attribute|0x0500;break;
case 110:attribute=attribute &0xf800;attribute=attribute|0x0600;break;
case 111:attribute=attribute &0xf800;attribute=attribute|0x0700;break;
}
}
/************************************************/
void setbackground(char x)
{
switch(x)
{
case 94:attribute=attribute &0xf800;break;
case 95:attribute=attribute &0xf800;attribute=attribute|0x01000;break;
case 96:attribute=attribute &0xf800;attribute=attribute|0x02000;break;
case 97:attribute=attribute &0xf800;attribute=attribute|0x03000;break;
case 98:attribute=attribute &0xf800;attribute=attribute|0x04000;break;
case 99:attribute=attribute &0xf800;attribute=attribute|0x05000;break;
case 100:attribute=attribute &0xf800;attribute=attribute|0x06000;break;
case 101:attribute=attribute &0xf800;attribute=attribute|0x07000;break;
}
}
/*************************************************/
 void clearscreen(void)
 {
 int addr;
 int far *farptr;
 farptr=(int far*)0xB8000000;
 if((fp=fopen (filename,"w"))==NULL)
 {
 printf("CAN NOT OPEN FILE screen.txt FOR SAVE SCREEN");
 return;
 }
 for(addr=0;addr<2000;addr++)
 *(farptr+addr)=getw(fp);
 fclose(fp);
 }
/************************************************/
       void helpuser(void){
       char c1,c2;
       int pagenumber=1;
       savescreen("temp.txt");
       loadscreen("help1.txt");
       while((c1=getch())!=27)
       {
       if(c1==0)
       {
       c2=getch();
       switch(c2)
       {
       case 73:
       switch(pagenumber)
       {
       case 2:
       pagenumber=1;loadscreen("help1.txt");break;
       case 3:
       pagenumber=2;loadscreen("help2.txt");break;
       case 4:
       pagenumber=3;loadscreen("help3.txt");break;
       case 5:
       pagenumber=4;loadscreen("help4.txt");break;
       }
       break;
       case 81:
       switch(pagenumber)
       {
       case 1:
       pagenumber=2;
       loadscreen("help2.txt");
       break;
       case 2:
       pagenumber=3;
       loadscreen("help3.txt");
       break;
       case 3:
       pagenumber=4;
       loadscreen("help4.txt");
       break;
       case 4:
       pagenumber=5;
       loadscreen("help5.txt");
       break;
 }
       break;
       }
       }
       }
       loadscreen("temp.txt");
       return;
       }
/*************************************************/
  /* end        */

تابع کوئیک سورت (Q-sort)

     #include <stdio.h>
     #include <conio.h>
     #include <alloc.h>
     /************************************/
     void quicksort(int* list,int min, int max)
     {
      int *small;
      int *large;
      int i,s=0,l=0,k;
      int pivot,pivotpos;
      if(max <= min)
      return;

      pivot = list[min];
      small=malloc(sizeof(int)*(max-min+1));
      large=malloc(sizeof(int)*(max-min+1));
      for(i = min + 1; i <= max; i++)
      {
       if(list[i] <  pivot)
 small[s++] = list[i];
       else
 large[l++] = list[i];
      }
      k=min;
      for(i = 0; i < s; i++)
       list[k++] = small[i];
      list[k++] = pivot;
      pivotpos = k - 1;
      for(i = 0; i < l; i++)
       list[k++] = large[i];
      free(small);
      free(large);
      quicksort(list,min,pivotpos-1);
      quicksort(list,pivotpos+1,max);
     }
     /************************************/
     void main()
     {
      int list[10];
      int i;
      clrscr();
      printf("\nPlease  enter 10 digits :\n");
      for(i=0;i<10;i++)
      {
       printf("Array[%d]=",i+1);
       scanf("%d\n",&list[i]);
      }
      printf("\nApplying quicksort...\n");

      quicksort(list,0,10);

      for(i=0;i<10;i++)
      {
       printf("%d ",list[i]);
      }
      getch();
     }
/************************************/

تابع فاکتوریل ماکزیمم

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

  void fact(int);
  void max(void);
       main()
      {
     clrscr();
     printf("enter number for x and y: ");
     max();
     getch();
      }
  void max(void)
    {
     int x,y,z;
     scanf("%d   %d",&x,&y);
     z=(x>=y)?x:y;
     printf("max=%d",z);
     fact(z);
     return;
    }
   void fact(int h)
    {
     int i;
     long int pard=1;
     for(i=2;i<=h;i++)
      pard*=i;
     printf("\n");
     printf("fact of max=  %ld",pard);
     return;
    }

ترانهاده ماتریس 3×3

#include <stdio.h>
#include <conio.h>
#include <math.h>
#define N 3
#define FALSE 0
void main()
{
int array_1[N][N],i,j;
int array_2[N][N]={0,0,0,0,0,0,0,0,0};
clrscr();
for (i=0;i<N;i++)
for (j=0;j<N;j++)
{
printf("Enter A[%d][%d]:\0",i,j);
scanf("%d",&array_1[i][j]);
array_2[j][i]=array_1[i][j];
}
printf("\n\n");
for (i=0;i<N;i++)
{
for (j=0;j<N;j++)
printf("%5d",array_2[i][j]);
printf("\n");
}
getch();
}