// …………………………………………………………برنامه اول……………………………………………………………………………………………………..

// ------------------------------------------------------------------------

 #include "stdafx.h"

#include "stdio.h"

#include "conio.h"

void  get_array(int[],int);

float mode(int[],int);

void  bubble(int[],int);

void  put_array(int[],int);

//void      replace(int,int);

 

int _tmain(int argc, _TCHAR* argv[])

{

      const int N=10;

      int         Numbers[N],len=1;

      while(len>0)

      {

            printf("\nEnter number of your data: ");

            scanf("%d",&len);

            get_array(Numbers,len);

            printf("The mode of your data is:%f",mode(Numbers,len));

           

            printf(" \nDo you want to sort the list:");

            if(getche()!='n')

            {

                  bubble(Numbers,len);

                  put_array(Numbers,len);

            }

 

      }

      return 0;

}

void get_array(int Data[],int Len)

{

      int i,x;

      for (i=1;i<=Len;i++)

      {

            printf("\n List number : %d Enter your Number: ",i);

            scanf("%d",&x);

            Data[i]=x;

           

      }

}

void put_array(int Data[],int Len)

{

      int i;

      printf(" \n--------------List of the number ---------------");

      for (i=1;i<=Len;i++)

            printf(" \n %d ) %d",i,Data[i]);

           

}

float mode(int Data[], int Len)

{

      int i,j,repeat,md_num=1,max=0;

      float out=Data[1];

      for (i=1;i<=Len;i++)

      {

            repeat=0;

            for(j=1;j

                  if (Data[i]==Data[j])

                        repeat=1;

            if(!repeat)

            {

                  for(j=1;j<=Len ;j++)

                        if (Data[i]==Data[j])

                              repeat++;

 

                  if ((repeat==max))

                  {

                        out=Data[i]+out*md_num;

                        md_num++;

                        out=out/md_num;

                  }

 

                  if (repeat>max)

                  {

                        out=Data[i];

                        md_num=1;

                        max=repeat;

                  }

            }

      }

      return out;

}

void bubble(int Data[],int Len)

{

      int i,j,temp;

      for (i=1;i

            for(j=i+1;j<=Len;j++)

                  if (Data[i]>Data[j])

                  {

                        temp=Data[i];

                        Data[i]=Data[j];

                        Data[j]=temp;

                  }

}

// ……………………………………………………………….برنامه دوم………………………………………………………………………………

//------------------------------------------------------------------------

 

#include "stdafx.h"

#include

#include

#include

#define     Name_len 20

void  Read_stud(int[],char[][Name_len],int);

int         Search( int [], char [][Name_len],int  ,char[] ,int);

//int       st[N_std];

//char      nam[Name_len][N_std];

 

int _tmain(int argc, _TCHAR* argv[])

{

      const int N_std=10 ;

      int         st[N_std],std_num,n,exist;

      char  nam_std[N_std] , nam[N_std][Name_len];

//    clrscr();

      printf("\nEnter number of students:");

      scanf("%d",&n);

      Read_stud(st,nam,n);

      printf("\nEnter the student number that you want to search:(0 if you don't want to search)");

      scanf("%d",&std_num);

      if (std_num !=0)

            exist=Search(st,nam,std_num , "" , n);

      else

      {

            printf("\nEnter the student name that you want to search:");

            scanf("%s",&nam_std);

            exist=Search(st,nam,0 , nam_std , n);

      }

      if (exist==-1)

            printf("The Student Name or Number could Not be find in the list");

      else

            printf("The name of the student is: %s and her/his Student Number is: %d",nam[exist],st[exist]);

     

      getch();

     

      return 0;

}

void Read_stud(int st[],char nam[][Name_len],int len)

{

      int i;

      for (i=1;i<=len;i++)

      {

            printf("\nlist number=%d Enter the student number:",i);

            scanf("%d",&st[i]);

            printf(" and Enter the student name:");

            scanf("%s",&nam[i]);

      }

}

int Search( int st[], char nam[][Name_len],int std_num ,char nam_std[],int len)

{

      int i,temp=-1;

      for(i=1;i<=len;i++)

            if (std_num==st[i] || !strcmp(nam_std,nam[i]))

            {

                  temp=i;

                  break;

            }

      return(temp);

}

 

// ………………………………………………………………………………برنامه سوم………………………………………………………………………………

// ----------------------------------------------------------------------

 

#include "stdafx.h"

#include

#include

#include

#include

void matget(int mat1[][],int mat2[][]); /*تعريف اوليه زير تابع */

void matmul(int mat1[1][m],int mat2[n][m]); /*تعريف اوليه زير تابع */

void matput(int mat1[][],int mat2[][]); /*تعريف اوليه زير تابع */

int _tmain(int argc, _TCHAR* argv[])

{

matget(int mat1[][],int mat2[][]);/* فراخوان زير تابع */

matmul(int mat1[1][m],int mat2[n][m]);/*فراخوان زير تابع */

matput(int mat1[][],int mat2[][]);/*فراخوان زير تابع */

      return 0;

}

 

void matget(int mat1[][],int mat2[][]);/* تعريف تابع */

{ int m1[2][3], m2[3][4], m3[2][4]={0} ;

     int i, j ;

 

 

       //read mat1

     for(i = 0 ; i < 2 ; i++)

       for(j = 0 ; j<3 ;j++)

       {

       printf("\nEnter m1[%d][%d]: ",i, j);

       scanf("%d", &m1[i][j]) ;

       }

     //read mat2

     for(i = 0 ; i < 3 ; i++)

       for(j = 0 ; j < 4 ; j++)

       {

       printf("\nEnter m2[%d][%d]: ",i, j);

       scanf("%d", &m2[i][j]) ;

         }

 

}

        

void matmul(int mat1[1][m],int mat2[n][m]);/* تعريف تابع */

{

      int i, j, k;

     //multiply mat1 by mat2

     for(i = 0 ; i < 2 ; i++)

      for(j = 0 ; j < 4 ; j++)

        for(k = 0 ;k < 3 ; k ++)

        {

            m3[i][j] = m3[i][j] + m1[i][k]* m2[k][j];

        }

}

 

void matput(int mat1[][],int mat2[][]);/* تعريف تابع */

{

     printf("\n\n\n Produc of mat1 & mat2 is : \n\n") ;

     for(i = 0 ;i < 2 ; i++) {

       for(j = 0 ; j < 4 ; j++)

        printf("%5d", m3[i][j]) ;

       printf("\n\n") ;

     }

// ……………………………………………………………چهارم برنامه ………………………………………………………………………………..

//  -------------------------------------------------------------------

 

#include "stdafx.h"

#include

#include

#include

bubble(int data[],int len,int endindex);/*تعريف اوليه زير تابع */

 

int _tmain(int argc, _TCHAR* argv[])

{

int beet;

bubble(int data[],int len,int endindex;/*فراخواني تابع*/

beet=len/2;

printf("\n beet=%d",beet);

      return 0;

}

 

void bubble(int data[],int len,int endindex){/*تعریف تابع */

 

      for(int i=len;i

 

             

                        if(data[i]>data[i+1]){

                              for(int k=i+1; data[k-1]>data[k] && k>0;k--){

                                    int t=data[k];

                                    data[k]=data[k-1];

                                    data[k-1]=t;

                              }

                     }

             

            }

}

 

void main(){

 

      float numbers[100];

      int index_last=0;

 

      for(int i=0;i<100;i++){

            printf("enter number :");

            scanf("%f",&numbers[index_last]);

            index_last++;

 

            char ch;

            printf("    continue(y/n)");

            scanf("%s",&ch);

            if(ch=='n'){break;}

      }

 

      bubble(numbers,0,index_last-1);

 

      printf("\nSorted:\n");

      for(int i=0;i

            printf("\n%f",numbers[i]);

      }

      getch();

}

// ……………………………………………………………………………… برنامه پنجم………………………………………………………………………………

//-------------------------------------------------------------------------

 

#include "stdafx.h"

#include

#include

#include

#include

#define EOLN '\n'

using namespace std;

/*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);

getch();

return;

 

}

//……………………………………………………………………………… برنامه ششم………………………………………………………………………………

//-----------------------------------------------------------------------

 

#include "stdafx.h"

#include

#include

int numDigit(int n){

   int ret=0;

 

   for(int t=1;n/t;t*=10){

            ret++;

   }

 

   return ret;

}

 

int Prim(int n){

 

      int ret=1;

 

      for(int i=2;i

            if(n%i==0){ret=0;}

      }

 

      return ret;

}

 

void main(){

     

      char ch='y';

      while(ch=='y'){

int n=0;

            printf("enter number :");

            scanf("%d",&n);

 

            for(int i=n-1;i>2;i--){

                  if(numDigit(i)

                  if(Prim(i)){

                        printf("\n%d",i);

                  }

            }

 

            printf("\ncontinue(y/n):");

            scanf("%s",&ch);

      }

 

      getch();

}

           

// ………………………………………………………………………………برنامه هفتم ………………………………………………………………………………

// ------------------------------------------------------------------------

 

#include "stdafx.h"

#include

#include

#include

 

void main(){

double answer=4;

double a=-1;

for(int i=3,j=1; i<=10000; i=i+2,j++){

answer = answer + ((pow(a,j))*((double)4/i));

}

cout<

 

getch();

}          

            int n=0;

            printf("enter number :");

            scanf("%d",&n);

 

            for(int i=n-1;i>2;i--){

                  if(numDigit(i)

                  if(Prim(i)){

                        printf("\n%d",i);

                  }

            }

 

            printf("\ncontinue(y/n):");

            scanf("%s",&ch);

      }

 

      getch();

}