اذهب إلى المحتوى

Mohamed Boussaid

الأعضاء
  • المساهمات

    2
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة Mohamed Boussaid

  1. #include <string.h>
    int mat[3][3] , b[9];
    int i  , j , k  ;
    /// 1
    void Add(){
      /* get the matrix entries from the user */
      printf("Enter your entries for the input mat:\n");
      for (i = 0; i < 3; i++) {
           for (j = 0; j < 3; j++) {
               scanf("%d", &mat[i][j]);
           }
      }
    }
    
    
    /// 2
    void RowTotal(){
    	for( i = 0; i < 3 ; i++){
    	for( j = 0; j < 3 ; j++){
    
    	Total+=mat[i][j];
    }
    printf("%d" , Total);
    
    }
    
    /// 3
    void CFunction(){
    
    
    for( i = 0; i < 3 ; i++){
    	for( j = 0; j < 3 ; j++){
    
    		if(i == j ){
    			printf("[%d]" , mat[i][j]);
    		}
    
    	}
    
    }
    
    }
    
    
    //// 4
    
    function SortMat(){
    
    // Convert All Array to 1d array 
    k =0 ;
    for(i=0;i<3;i++) 
        {
            for(j=0;j<3;j++)
             b[k++]=mat[i][j];
        }
    
    
     /// sort the 1d array 
     int temp ;
       for (i=0;i<9;i++)
        {
             for (j=0;j<(8-i);j++)
            {
                   if(b[j]>b[j+1])
                {
                     temp = b[j];
                    b[j] = b[j+1];
                    b[j+1] = temp;
                }
            }
        }
    /// conver 1d to 2d 
    
    
     k=0;
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                arr[i][j]=b[k];
                k++;
            }
     
        }
    
    }
    
    int Max(){
    int matmax = mat[0][0];
    
    for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                if(mat[i][j] > matmax){
    matmax = mat[i][j];
    
    }
            }
            
        }
    return matmax;
    
    }
    
    ///6
    
    
    void PrintArr(){
    
    for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                printf("%d ",mat[i][j]);
            }
            printf("\n");
        }
    
    
    }
    
    /// 7 
    void Total(){
    int Tot = 0 ;
    for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                Tot+=mat[i][j];
            }
            
        }
    
    
    printf("\nTotal is : %d" , Tot);
    
    
    }
    
    }
    
    void Main(){
     // call function here
    Add();
    RowTotal();
    CFunction();
    SortMat();
    printf("%d" , Max());
    PrintArr();
    Total();
    
    
    }
    

    Exe.c

    • أعجبني 2
×
×
  • أضف...